graphile | graphics files | File Utils library
kandi X-RAY | graphile Summary
kandi X-RAY | graphile Summary
graphics files processor
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of graphile
graphile Key Features
graphile Examples and Code Snippets
Community Discussions
Trending Discussions on graphile
QUESTION
Is it possible to access pgSettings
in a PostGraphile plugin, specifically makeExtendSchema
? Here is my middleware:
ANSWER
Answered 2021-Jun-12 at 20:13additionalGraphQLContextFromRequest
is great. But I would have to create the entire resolver. Instead I created a custom mutation:
QUESTION
How would one go about defining extended permissions and authorization on a many-to-many relationship using Postgraphile?
Imagine I have this many-to-many relationship (graciously borrowed from official docs and adjusted with simplified permissions):
...ANSWER
Answered 2021-Feb-16 at 20:13Based on investigation and trial-and-error, this seems to be something that is best solved with a custom function for updating posts.
An owner can use this function via GraphQL/Postgraphile:
QUESTION
I have a project where I have updated all of the packages.
Before the update all e2e tests functioned as expected.
After the update, The product itself compiles and runs as expected.
However, the e2e tests are showing unexpected issues both in the IDE and at run time.
For example,
...ANSWER
Answered 2021-Jan-21 at 19:52Finally figured out a solution after visiting the NPM page for axe-cypress.
QUESTION
I just spend more than a day trying to understand this. I'm working on a new hobby project and wanted to learn GraphQL. This is my current setup:
Server:
- PostGreSQL db (docker)
- Graphile server (docker)
- configured via docker-compose, both images run on the same physical server, but have different ports.
Client:
- Angular front end
- Apollo client via apollo-angular package
- currently in dev, so host = localhost
I can call my API via postman without problems. But when I run the code from my client, I get the expected "Origin http://localhost:4200 is not allowed by Access-Control-Allow-Origin." error.
This is my docker-compose.yml:
...ANSWER
Answered 2020-Oct-05 at 09:05I found the solution to my problem!
I found that in my case the Access-Control-Allow-Origin error was due to my browser blocking the outward call to my API. My endpoint was never reached in the first place. So any configuration on the server level should not be done at this stage of the problem solving.
What I ended up doing is configuring a proxy in my Angular app.
My graphile server is listening on http://xxx.xxx.xxx.xxx:xxxx/graphql endpoint.
In the source root of my Angular app I created a file called proxy.conf.json
:
QUESTION
I am trying typegraphql with apollo-server, typeorm, bcrypt with the below resolver in typescript. When the mutation query is run it throws the error 'Cannot return null for non-nullable field Mutation.create'. But it is saving the data to database with hashed password (also i can infer this for sure by using console.log); Only the mutation query is throwing error in browser.
Here is mutation resolver:
...ANSWER
Answered 2020-Jul-05 at 04:46I'm not positive, but I see a few things that might be causing this.
In your first code snippet, the only return statement is inside the callback function passed to
then
. So thecreate
method does not return anything.I looked at the src for typeORM... it looks like
Repository.save()
returnsPromise
(notPromise
) when the input value is a single entity object (see Repository.ts). If this is the case, your GraphQL schema would be expecting this mutation to return an array of users, but the resolver is returning a single user.
Try changing the return type to Promise
QUESTION
I'm working on a GraphQL API which sits in front of a REST service. This REST service is a single endpoint with a lot of complex parameters - rather than put all the parameters on a single GraphQL field, we've logically broken it down into a tree of GraphQL fields and types.
In particular, the bottom of this tree is somewhat dynamic and unbounded. All in, it looks something like this simplified schema:
...ANSWER
Answered 2020-Apr-11 at 20:23GraphQL's top-down way of executing requests doesn't really lend itself to resolvers building up a query that would be executed once all resolvers are ran. In part, this is because the parent field's resolver has to complete execution before any child field resolvers are called. After all, they need to be called with the value that the parent resolved to.
If you had multiple calls to your datasource, it might make sense to split them across different resolvers. If you only need to make a single call to your datasource, though, doing so at the top level and using "lookahead" is the best approach. graphql-parse-resolve-info
is an excellent library to help with that.
The only improvement over what you're doing now might be to move most of the logic for transforming the REST response into the resolvers for some of your non-root fields. In this way, you can gradually transform the parent
value passed to each resolver as the execution moves through each "level" of your query.
QUESTION
PostGraphile does NOT recommend column-level SELECT grants, instead recommends to
split your concerns into multiple tables and use the one-to-one relationship feature to link them.
Now I want my users
table to have a role
field that can be accessed by role_admin
but not by role_consumer
. Based on the above recommendation, I created two tables. users
table (in public schema) contains all fields that both roles can see, and user_accounts
(in private schema) contains role
field that only role_admin
must be able to see. role
field is added to the user
GraphQL type via computed columns.
ANSWER
Answered 2020-Feb-25 at 21:18For option 1, throwing an error from PostgreSQL during a query is not a good idea in PostGraphile because we compile the entire GraphQL tree into a single SQL query, so an error aborts the entire query. Instead, I would factor the permissions into the function and simply return null (rather than an error) if the user is not allowed to view it. One way to do this is with an additional WHERE
clause:
QUESTION
newbie in SQL coming from a JS world needing some advice on triggers.
My user has an id
column and my GraphQL API always calls INSERT INTO .... RETURNING *
and then doing the transforms on the GraphQL layer to return what I want.
The goal is to allow a query like INSERT INTO .... RETURNING *
work with RLS in place.
The policies are:
...ANSWER
Answered 2020-Feb-20 at 11:47Your don't say what a guest is, but your approach seems wrong.
Rather than disabling your checks on a low level, which gives you a bad feeling for good reasons, you should choose one of the following approaches:
fix your policies to allow the necessary operation (perhaps by adding a permissive policy)
have certain operations performed by a
SECURITY DEFINER
function that belongs to a user not subject to the restrictions.
If you insist on a trigger based solution, you have to use a BEFORE
trigger. Also, consider that you cannot use parameterss with a SET
statement. You'd either have to use dynamic SQL or (better) use a function:
QUESTION
Is there a way to disable the 'remove-the-plural-s' feature in Postgraphile?
I have a table OS
in my database and am using the very awesome Postgraphile library to create a GraphQL interface for free. Everything is great, but Postgraphile is truncating my table name, thinking it is plural. So I get allOs
instead of allOses
and createO
, updateO
, etc...
I tried:
- Adding an underscore after the table name, and then it just retains the entire thing with an underscore.
- Adding an underscore (
O_S
) and then the plural has capital-sallOS
but the singular isO_
- A smart comment specifying
E'@name os'
but it still drops thes
- A smart comment specifying
E'@name oss'
which then pluralizes correctlyallOsses
(haha) and keeps both for the singulaross
PS in case you see this Benjie/other contributors, your documentation is incredible and the library will save me months of work.
...ANSWER
Answered 2019-Feb-02 at 18:44This change is performed by PostGraphile's inflector; however it doesn't always get it right (e.g. in this case) but fortunately it's possible to override it with a small plugin.
In this case, it's probably best to add specific exceptions to the pluralize
and singularize
functions; you can do this using makeAddInflectorsPlugin from our inflection system. Be sure to pass true
as the second argument so that the system knows you're deliberately overwriting the inflectors.
QUESTION
My company has a service-oriented architecture. My app's GraphQL server therefore has to call out to other services to fullfill the data requests from the frontend.
Let's imagine my GraphQL schema defines the type User
. The data for this type comes from two sources:
- A user account service that exposes a REST endpoint for fetching a user's
username
,age
, andfriends
. - A SQL database used just by my app to store
User
-related data that is only relevant to my app:favoriteFood
,favoriteSport
.
Let's assume that the user account service's endpoint automatically returns the username
and age
, but you have to pass the query parameter friends=true
in order to retrieve the friends
data because that is an expensive operation.
Given that background, the following query presents a couple optimization challenges in the getUser
resolver:
ANSWER
Answered 2019-Aug-26 at 01:52If you want to modify your resolver based on the requested selection set, there's really only one way to do that and that's to parse the AST of the requested query. In my experience, graphql-parse-resolve-info
is the most complete solution for making that parsing less painful.
I imagine this isn't as common of an issue as you'd think because I imagine most folks fall into one of two groups:
- Users of frameworks or libraries like Postgraphile, Hasaura, Prisma, Join Monster, etc. which take care of optimizations like these for you (at least on the database side).
- Users who are not concerned about overfetching on the server-side and just request all columns regardless of the selection set.
In the latter case, fields that represent associations are given their own resolvers, so those subsequent calls to the database won't be fired unless they are actually requested. Data Loader is then used to help batch all these extra calls to the database. Ditto for fields that end up calling some other data source, like a REST API.
In this particular case, Data Loader would not be much help to you. The best approach is to have a single resolver for getUser
that fetches the user details from the database and the REST endpoint. You can then, as you're already planning, adjust those calls (or skip them altogether) based on the requested fields. This can be cumbersome, but will work as expected.
The alternative to this approach is to simple fetch everything, but use caching to reduce the number of calls to your database and REST API. This way, you'll fetch the complete user each time, but you'll do so from memory unless the cache is invalidated or expires. This is more memory-intensive, and cache invalidation is always tricky, but it does simply your resolver logic significantly.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install graphile
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page