graphql-tools
graphql-tools copied to clipboard
Nested fields of @computed parent are not resolved
Issue workflow progress
Progress of the issue based on the Contributor Workflow
- [x] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox
Make sure to fork this template and run
yarn generate
in the terminal.Please make sure the GraphQL Tools package versions under
package.json
matches yours. - [ ] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review
Describe the bug
Schema (User Service):
type User @canonical {
id: ID!
name: String!
organizationId: String!
}
Schema (Organization Service):
type Organization {
id: ID!
name: String!
users: [User!]
}
type User @key(selectionSet: "{ id }") {
id: ID!
organization: Organization @computed(selectionSet: "{ organizationId }")
}
Query:
query DoesNotWork {
users(ids: ["1", "2"]) { # user service
name
organization { # organization service with @computed directive
name
users { # user service
name
}
}
}
}
We have two services (User, Organization). Inside the Organization service we want to extend the type User
with the field organization
. Therefore we have to use the @computed
directive. The type returned by the directive (in our case Organization
) includes fields that must be resolved by the User service. This does not work and throws following error: Error: Cannot return null for non-nullable field User.name.
To Reproduce Steps to reproduce the behavior:
Open Sandbox and execute the default query named "DoesNotWork" in GraphiQL.
Expected behavior
Nested fields combined with the @computed
directive are always resolved correctly.
Environment:
-
@graphql-tools/schema": "^10.0.2"
-
@graphql-tools/stitch": "^9.0.3"
-
@graphql-tools/stitching-directives": "^3.0.0"
- NodeJS: v20