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
Dataloader for each field #64
Comments
The answers to this are going to vary widely and depend a lot more on your storage model than your API design. Typically dataloaders correspond to individual "types" of information in storage - that's usually a table in SQL style storage. For most apps, a type in storage corresponds to a type in GraphQL, so I would expect to see a data loader for "Post" and a data loader for "Comment" unless storage was organized in a different way. It's common to see a collection of loaders passed as part of the "context" variable in GraphQL so they're always available and unique per request. You can read more about these patterns on the README for this repo on "Using with GraphQL" and "Common Patterns" https://github.com/facebook/dataloader#using-with-graphql |
I believe one of the great features of GraphQL is to know exactly which fields to fetch, so would be interest to have a standard way of fetching only the needed information from the database and not the whole document once the user is requesting only a few fields, i believe that is the motivation behind @shakaIsReal issue, am i right @shakaIsReal ? i'm also trying to figure out a lean way of fetching the smallest amount of data from the database |
Please refer to: graphql/graphql-js#623 first, these issues are linked.
Let's say I'm querying this:
What happens on server:
id
is fetchedtitle
is fetched ( through dataloader? ) and thencomments
How would you use dataloader for loading data for each field? Create one instance per field e.g.
const title = new Dataloader( ...load posts's title... )
?But in this case
title
would be cached, and if user changes data - logic should be applied to update each loader separately (based on fields defined in the type that use dalataloader)And where do you store all the loaders? It seems like a common practice to store them in an object e.g.
const loaders = { .. loaders .. }
@leebyron @josephsavona
Relay/graphql boilerplate has code that lightly touches on this topic: https://github.com/codefoundries/UniversalRelayBoilerplate/blob/master/graphql/ObjectManager.js#L162 check it out.
It would be nice if devs could provide some docs on this topic
The text was updated successfully, but these errors were encountered: