ardatan / ardatan/graphql-tools
Nested fields of @computed parent are not resolved
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 830
- Avg merge
- 10h 59m
- Merged PRs (30d)
- 45
Description
### Issue workflow progress
_Progress of the issue based on the
[Contributor Workflow](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md#a-typical-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):
```gql
type User @canonical {
id: ID!
name: String!
organizationId: String!
}
```
Schema (Organization Service):
```gql
type Organization {
id: ID!
name: String!
users: [User!]
}
type User @key(selectionSet: "{ id }") {
id: ID!
organization: Organization @computed(selectionSet: "{ organizationId }")
}
```
Query:
```gql
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](https://codesandbox.io/p/devbox/condescending-dewdney-zzk552) 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
Contributor guide
Research direction
Run the linked CodeSandbox and its default “DoesNotWork” query first to reproduce the failure. Then inspect @graphql-tools/stitch and @graphql-tools/stitching-directives, focusing on @computed resolution, and add a regression test for the demonstrated schema. Done means nested User fields under the computed Organization resolve without the non-null name error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100