ardatan / ardatan/graphql-tools

Merging directive arguments from extensions doesn't consider list input coercion

Open
#4,339 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.