How to use @DgsData.List for returning multiple fields #899
Replies: 2 comments 1 reply
-
|
With @DgsData.List, you can use the same data fetcher for resolving
`movies` and `shows` independently. In other words, when `graphql-java` is
resolving `movies` or `shows` it will invoke this data fetcher. It will not
resolve both at the same time. Hope that answers your question.
…On Tue, Mar 1, 2022 at 1:29 PM Bryan Cantos ***@***.***> wrote:
Currently have a graphql object returning fields from different sources
and I'm looking to leverage @DgsData.List. I found this #574
<#574> and this
https://netflix.github.io/dgs/datafetching/ (under Multiple @DgsData
Annotations Via @DgsData.List) but these don't tell me how to return back
different results using DgsData.List
For example, if we have this
type Query {
movies: [Movie]
shows: [Show]
}
I would like to resolve movies and shows somehow like this
@DgsData.List(
DgsData(parentType = "Query", field = "movies"),
DgsData(parentType = "Query", field = "shows")
)fun getMoviesAndShow(dfe: DataFetchingEnviornment): Query {
val query = repo.getMoviesAndShows()
return query // contains movies and shows
}
Is something like this possible?
—
Reply to this email directly, view it on GitHub
<#899>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ5JPXN7S7DYQ6OUYTJTQWLU52D2NANCNFSM5PVGV6WQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
BCantos17
-
|
As you mentioned, this should be a caching concern handled at the
application layer. If you know that both movies and shows are going to be
fetched at some point, then the data fetcher should be optimized to
return the cached value if the data already exists. Fundamentally,
`graphql-java` needs to know what data fetcher to call for a field. It is
up to the user to implement the same shared data fetcher or distinct ones.
…On Wed, Mar 2, 2022 at 6:44 AM Bryan Cantos ***@***.***> wrote:
I see, so it will call the data fetcher twice in my example. I suppose I
could implement caching in order to avoid calling the same data source
twice.
Still I think it might be a good feature to have, having two data fetcher
for resolving multiple different fields in one query, considering the
nature of graphql. Has this ever been discussed?
—
Reply to this email directly, view it on GitHub
<#899 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ5JPXLBFVCEXJ4MWT6L6CDU555DTANCNFSM5PVGV6WQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently have a graphql object returning fields from different sources and I'm looking to leverage
@DgsData.List. I found this #574 and this https://netflix.github.io/dgs/datafetching/ (under Multiple @DgsData Annotations Via @DgsData.List) but these don't tell me how to return back different results using DgsData.ListFor example, if we have this
I would like to resolve movies and shows somehow like this
Is something like this possible?
Beta Was this translation helpful? Give feedback.
All reactions