-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass previous object to resolvers #2206
Comments
@cjelger Sorry for the confusion we definitely need to update our docs.
We actually have two types of resolvers:
|
Thanks @IvanGoncharov, using |
@cjelger It should work, see here for a complete example: https://github.com/graphql/graphql-js/blob/eef0878d851f7b8a4392b031550a1080497c018c/src/__tests__/starWarsSchema.js |
@IvanGoncharov Thank you for your reply. I will try this again based on the example/test ... it's pretty much what I tried with minor differences. |
Hello, this one bit me too. I am using graphql-code-generator to generate Typescript resolvers. The resolver function signature matches the Graphql specification: export type ResolverFn<TResult, TParent, TContext, TArgs> = (
parent: TParent,
args: TArgs,
context: TContext,
info: GraphQLResolveInfo
) => Promise<TResult> | TResult; But when I write a simple resolver for hello: (...args) => {
console.log({ args })
return {
greeting: "Hello"
}
}, I see that the parent is not passed
What is the recommended fix or workaround for this? |
Update: using makeExecutableSchema works perfectly. |
Feature requests
Based on the documentation at https://graphql.org/learn/execution/#root-fields-resolvers, I expected that resolvers would always receive the parent/previous object as the first argument. However when I tested the library, the arguments received by the resolvers are actually
(args, context, info)
.This doesn't match the documentation, and is a serious limitation when one needs the parent object (for example, some
id
) in order to resolve children fields.Is there a workaround or is this a known limitation?
The text was updated successfully, but these errors were encountered: