graphql-tools
graphql-tools copied to clipboard
Directives on root fields are lost in subschema requests
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 generatein the terminal. > > Please make sure the GraphQL Tools package versions underpackage.jsonmatches yours. - [x] 2. A failing test has been provided
- [x] 3. A local solution has been provided
- [ ] 4. A pull request is pending review
Describe the bug
When I use directive on the root field, the @graphql-tools/delegate loses directive on subschema request.
To Reproduce Steps to reproduce the behavior:
- Make schema with custom directive on FIELD and query with root field.
directive @strExpr on FIELD
type Query {
hello: String
}
- Stitch single schema with mergeDirectives (maybe can be replaced with delegateToSchema but idk how).
- Pass graphql request to stitched schema with directive on root field.
query getHello {
hello @strExpr
}
- The request passed to resolver has no directive on the root field.
query getHello {
__typename
hello
}
Try online https://codesandbox.io/p/devbox/stitching-directives-vvp6xj
Expected behavior
There is a directive on the request, as well as on the original request.
query getHello {
__typename
hello @strExpr
}
Environment:
- OS: windows 10
@graphql-tools/delegate: 10.0.11- NodeJS: v18.18.2
My solution
Add to object rootfieldNode in @graphql-tools/delegate/cjs/createRequest.js directives: fieldNodes?.[0]?.directives to pass directives to new request.
Additional context
I am not sure enough, but maybe mergedOperationDefinition also requires directives support for operations?