How to access parent input argument from child data fetcher #23
-
I have a graphQL schema, type Query {
getContact (customerId: ID!): Contact
}
type Contact {
email: String
address: [Address]
}
type Address {
street: String!
number: String!
additional: String
pincode: String!
city: String!
country: String!
} I generated the data models using the codegen plugin and wrote 2 data fetchers (contact and address). In the contact data fetcher, I can access the code: @DgsComponent
class ContactFetcher(
private val addressService: AddressService
) {
@DgsData(parentType = DgsConstants.QUERY_TYPE, field = DgsConstants.QUERY.GetContact)
fun contact(@InputArgument("customerId") customerId: String): Contact =
Contact(email = "[email protected]") // here I can access the customerId
@DgsData(parentType = DgsConstants.CONTACT.TYPE_NAME, field = DgsConstants.CONTACT.Address)
fun address(dfe: DataFetchingEnvironment): List<Address> {
/* I need to fetch the address based on the customer Id. but how to access customerId here?
I tried dfe.arguments which is an empty map. @InputArgument does not work also.*/
return addressService.getAddresses(customerId)
}
}
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
What you're likely looking for is the |
Beta Was this translation helpful? Give feedback.
-
That is a great suggestion since this is a common use case. We will add
this to the roadmap.
…On Sun, Feb 7, 2021 at 9:41 AM Driptaroop Das ***@***.***> wrote:
Thank you @paulbakker <https://github.com/paulbakker> . I replied in the
other thread.
Thank you @srinivasankavitha <https://github.com/srinivasankavitha> as
well. I indeed got the value by this way although this is a very verbose
way of getting it. A more intuitive way of getting the root arguments would
make the usage a bit easier. I am thinking some annotation based method
parameter injection (something like @RootArguments, working similarly as
@InputArgument but for root arguments). Is there something like this on
the feature roadmap for DGS since this might be a common use case?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ5JPXLWBZXMH34OZDJWYXDS53GGFANCNFSM4XDYBNWA>
.
|
Beta Was this translation helpful? Give feedback.
-
Created a new issue for this - #36 |
Beta Was this translation helpful? Give feedback.
Created a new issue for this - #36