DgsEntityFetcher optimization #1210
Unanswered
jacobo-cloudbeds
asked this question in
Q&A
Replies: 1 comment 3 replies
-
Have you considered using a data loader which will batch all the calls for
fetching reviews. You won't be able to avoid the N calls to reviewsFetcher,
but reviewsFetcher can use a dataloader which will optimize the fetching
from other backends/datastores etc.
…On Wed, Aug 31, 2022 at 6:01 AM jacobo-cloudbeds ***@***.***> wrote:
Hi!
I'm testing GraphQL Federation with DGS and while replicating the example
from the docs I realized that movie and reviewsFetcher are called N times
(once per Show), but reviews could be fetched for all shows in a single
query more efficiently. I guess I could use the DgsDataFetchingEnvironment
to get access to the representations argument the first time movie is
called, fetch all reviews for all shows, and store them in the context to
return them later when reviewsFetcher is called. I wonder if there is a
better/more elegant way to do it.
@DgsEntityFetcher(name = "Show")
public Show movie(Map<String, Object> values) {
return new Show((String) values.get("id"), null);
}
@DgsData(parentType = "Show", field = "reviews")
public List<Review> reviewsFetcher(DgsDataFetchingEnvironment dataFetchingEnvironment) {
Show show = dataFetchingEnvironment.getSource();
return reviews.get(show.getId());
}
Thanks!
—
Reply to this email directly, view it on GitHub
<#1210>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ5JPXMX47N2KA2Z6477QBDV35JSDANCNFSM6AAAAAAQBLK5YY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
I'm testing GraphQL Federation with DGS and while replicating the example from the docs I realized that
movie
andreviewsFetcher
are called N times (once per Show), but reviews could be fetched for all shows in a single query more efficiently. I guess I could use theDgsDataFetchingEnvironment
to get access to therepresentations
argument the first timemovie
is called, fetch all reviews for all shows, and store them in the context to return them later whenreviewsFetcher
is called. I wonder if there is a better/more elegant way to do it.Thanks!
Beta Was this translation helpful? Give feedback.
All reactions