-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: How to do batching? #235
Comments
. |
@edgard Yes, it is possible to use dataloader with this library. Here's an example:
This would result in two batches ([#1] and [#2]), because resolvers must return a value, not "something that yields a value eventually" (such as a channel or a thunk). We can solve this by either resolving fields in parallel (#132) or asynchronously (#213) as done in the reference implementation https://github.com/graphql/graphql-js. Please correct me if I'm wrong. |
Thanks a lot for the great feedback guys! 👍 — I've created a new repo: graphql-dataloader-sample which shows how to do batching, closing this one. |
Lets say you have a list of movie, each movie have a list of actor, producer and director. And each actor have a list of movie their acted in. If we draw this like a tree, it would look like this:
The current implementation of the query resolves each item separately. If each resolver were to resolve by a database query. Let the number of movies is N, actors have joined M movies in average, directors have P movies in average. Then the above graph will be consist of:
And the number of queries goes up exponentially.
From what I read in other source, NodeJS server implementations usually have a loader layer (such as facebook/dataloader to help reducing the number of data fetching query. This pattern rides on the execution sequence of NodeJS (resolves all promise before return).
So the above graph would result in this
The key is to gather all specify the entities to load when doing resolve, then resolve them in 1 single batch. Also with a load of caching, the number of entities to query can be even drive down.
The question is, how do you similar thing in graphql-go?
The text was updated successfully, but these errors were encountered: