ardatan / ardatan/graphql-tools
Merging directive arguments from extensions doesn't consider list input coercion
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 830
- Avg merge
- 10h 59m
- Merged PRs (30d)
- 45
Description
**Describe the bug**
When adding an already defined directive through an extension statement, it appears that `mergeTypeDefs` attempts to merge the arguments of duplicated directives if the original was of list type. If the extension directive relies on list input coercion by not specifying a list, an exception is thrown.
**To Reproduce**
Steps to reproduce the behavior:
```javascript
const { mergeTypeDefs } = require('@graphql-tools/merge');
const { parse } = require('graphql');
const merged = mergeTypeDefs(
parse(
`
directive @foo(x: [Int!]!) repeatable on SCALAR
scalar Foo @foo(x: [1])
extend scalar Foo @foo(x: 2)
`
)
);
```
**Expected behavior**
Script runs to completion successfully. Instead it ends in `TypeError: Cannot read property 'filter' of undefined`
**Environment:**
- OS: Windows
- `@graphql-tools/merge`: 8.2.6
- `graphql`: 16.3.0
- NodeJS: v14.17.6
Contributor guide
Research direction
Start by running the provided reproduction through mergeTypeDefs and inspect the directive-argument merging path. Done means the list-coercion example completes without the TypeError and preserves the expected merged directive arguments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100