How to fetch association from field datafetcher #21
-
This is a bit of a follow up to #18 but the question is different. Let's take this example:
The codegen generates a And the implementing data fetchers could be something like:
In the director data fetcher I could retrieve the persistent Show (again) - using like I wonder if there is a better way? PS: Without DGS my Show class returned by the shows datafetcher would contain the |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 11 replies
-
I think I understand the problem; to be able to load the director you need a field that your internal datas structure has, but is not represented in the schema, and thus not on the generated type. This problem is introduced because the |
Beta Was this translation helpful? Give feedback.
-
@marceloverdijk I've created a PR with new docs showing the different options around this topic if you want to review: Netflix/dgs#10. |
Beta Was this translation helpful? Give feedback.
-
To reduce the amount of boilerplate code, but still using the type Show {
@internal id: ID
title: String
reviews: [Review]
} The framework could then ignore all fields annotated with |
Beta Was this translation helpful? Give feedback.
I think I understand the problem; to be able to load the director you need a field that your internal datas structure has, but is not represented in the schema, and thus not on the generated type.
If you return an instance of the generated type from the
shows
data fetcher, that's what you get back fromgetSource
.This problem is introduced because the
director
data fetcher requires context that's only available in theshows
data fetcher. I'm sure there are multiple ways to get this to work, but my first approach would be to create a DataLoader to load directors, and invoke that data loader from within theshows
data fetcher where you still have thedirectorId
.