best practice to load many relations ids from database #93
Replies: 4 comments 1 reply
-
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 |
Beta Was this translation helpful? Give feedback.
-
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 ? |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
@bbakerman Hey, I'm trying to model a many-to-many, similar to this discussion and getting I'm trying to do Any advise on how to fetch that properly? |
Beta Was this translation helpful? Give feedback.
-
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?
Beta Was this translation helpful? Give feedback.
All reactions