You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey,
One of the steps that are required to support querying databases using GraphQL, is to expose the required selectionSet in the resolve functions. That way, users could use that to project only the required fields, thus optimizing the database's query performance and minimizing the network traffic between the GraphQL server and the DB server.
For example, for the following query:
{
user(id: 1) {
name,
email
}
}
I would get this as an argument for the resolve function on the user field in the GraphQL Schema: [ 'name', 'email' ] (or something similar). This way I could project only those fields from the DB query.
I realize I can access the "root" selectionSet on the fourth paremeter (operation.selectionSet) in the resolve function, but this can get a bit messy for complex query. I'm looking for a way to expose only the required selection: under the user's resolve I would get only the selected user fields, and under "whatever"'s resolve I would get only "whatever"'s selected fields and so on...
I realize that supporting databases isn't your top priority right now, but I'm just looking for directions, maybe I'd could implement this on my own somehow.
The text was updated successfully, but these errors were encountered:
I definitely suggest the approach taken by graphql-fields if this in the information you're looking for.
I would also suggest you consider performance tests for larger real-world queries under that assumption - what I've found is that querying an entire row (or at least the common subset available) can often result in improved global performance due to the opportunity for batching and caching when multiple values or types of values are fetched more than once during the operation of a query.
A lot of this may depend on your exact use case, schema, or database config, so YMMV.
Hey,
One of the steps that are required to support querying databases using GraphQL, is to expose the required selectionSet in the resolve functions. That way, users could use that to project only the required fields, thus optimizing the database's query performance and minimizing the network traffic between the GraphQL server and the DB server.
For example, for the following query:
I would get this as an argument for the resolve function on the user field in the GraphQL Schema:
[ 'name', 'email' ]
(or something similar). This way I could project only those fields from the DB query.I realize I can access the "root" selectionSet on the fourth paremeter (
operation.selectionSet
) in the resolve function, but this can get a bit messy for complex query. I'm looking for a way to expose only the required selection: under the user'sresolve
I would get only the selected user fields, and under "whatever"'sresolve
I would get only "whatever"'s selected fields and so on...I realize that supporting databases isn't your top priority right now, but I'm just looking for directions, maybe I'd could implement this on my own somehow.
The text was updated successfully, but these errors were encountered: