My GraphQL query looks like this:
{
p1: property(someArgs: "some_value") {
id
nestedField {
id
moreNestedField {
id
}
}
}
}
On the server side, I'm using Apollo Server.
I have a resolver for the property
and other resolvers for nestedField
and moreNestedField
.
I need to retrieve the value of someArgs
on my nested resolvers.
I tried to do this using the context
available on the resolver:
property: (_, {someArgs}, ctx) => {
ctx.someArgs = someArgs;
// Do something
}
But this won't work as the context is shared among all resolvers, thus if I have multiple property
on my query, the context value won't be good.
I also tried to use the path
available on info
on my nested resolvers. I'm able to go up to the property
field but I don't have the arguments here...
I also tried to add some data on info
but it's not shared on nested resolvers.
Adding arguments on all resolvers is not an option as it would make query very bloated and cumbersome to write, I don't want that.
Any thoughts?
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…