ardatan / ardatan/graphql-tools

Schema stitching results in query directives to be omitted

Open
#7,660 1 comment 1 reaction 0 assignees View on GitHub
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)_

- [ ] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox
> Make sure to fork this template and run `npm run 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**

Using `stitchSchemas({ mergeDirectives: true })` results in directives on queries to be omitted from the operation definition. Directives from other places (e.g. fields in the query) are preserved.

Schema:

```graphql
directive @test on QUERY | FIELD

type Query {
hello: String
}
```

Request:

```graphql
query Hello @test { # this is lost
hello @test # this is preserved
}
```

Parsed query:

```graphql
query Hello {
__typename
hello @test
}
```

**To Reproduce** Steps to reproduce the behavior:

https://codesandbox.io/p/devbox/graphql-schema-stitching-kx4lvh

**Expected behavior**

All directives are present in `OperationDefinitionNode` in resolvers.

**Environment:**

- OS: OSX
- `@graphql-tools/stitch`: `10.1.1`
- NodeJS: 22

Contributor guide

Open the contributing guide

Research direction

Start with the linked CodeSandbox reproduction and the stitchSchemas({ mergeDirectives: true }) path; inspect how the query's OperationDefinitionNode is produced. Done means the @test directive on the operation is preserved, while the existing field directive remains preserved, with a regression test covering the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, node.js, typescript
Domain
api, backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.