graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Directives on root fields are lost in subschema requests

Open kemper0110 opened this issue 1 year ago • 0 comments

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.
  • [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:

  1. Make schema with custom directive on FIELD and query with root field.
      directive @strExpr on FIELD
      type Query {
          hello: String
      }
  1. Stitch single schema with mergeDirectives (maybe can be replaced with delegateToSchema but idk how).
  2. Pass graphql request to stitched schema with directive on root field.
      query getHello {
          hello @strExpr
      }
  1. 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?

kemper0110 avatar Jun 27 '24 06:06 kemper0110