-
Notifications
You must be signed in to change notification settings - Fork 94
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
best practice to load many relations ids from database #34
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
Comments
Really what you are doing here is getting the "friends ids" of the character AND then loading those friends. So we need a batch loader that does those 2 operations at the same time. So I think you might want to combine them into one batch loader that takes a "characterID" and can find friends for them all in the one step So imagine your batch loader is like this (psudeo java code)
Now it might be that your database tables can only "find the ids of friends" in one query and then |
Hi @bbakerman Thanks for your reply. I create a dataloader for the relation between characterId and the list of Friend. It works like a charm ! Just to be sure to understand, to load friends by characterIds, i create a dataloader that store the list of friends by characterId ( Is it possible to load the friends id and next use a Friend's dataloader to get the Friends, all of that in an async way ? |
This issue actually looks like the same thing I'm asking about in #36. @bbakerman, do you have an example of how the batch loader you pseudo-coded above would be used? This differs from the examples, since in the examples the IDs of the objects you want to load are passed to the dataloader, whereas here it seems you need to pass the ID of the source object. I'm not sure how that should look in usage. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I try to implement a solution that uses graphql-java and dataloader over a database.
I would like to know the best pratice to load a many relations when the nested ids required a database query.
in the documentation example, imagine that we replace
starWarsCharacter.getFriendsIds()
by a database querygetFriendIdsFromDB(starWarsCharacter)
.The
friendsDataFetcher
would looks like :In this case it generates again a N+1 fetch problem. For each Character we have to query for the friends ids.
How to efficiently manage that case with the dataloader?
The text was updated successfully, but these errors were encountered: