graphql-tools
graphql-tools copied to clipboard
Repeatable directives from extensions merged incorrectly
trafficstars
Describe the bug
When specifying an additional directive in an extension statement, all directives of the same name are merged into one, with the arguments merged for list types. This behavior makes sense for non-repeatable directives.
When a directive is marked as repeatable, no merging should happen, though.
To Reproduce Steps to reproduce the behavior:
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]) @foo(x: [2])
extend scalar Foo @foo(x: [3])
`
)
);
const directives = merged.definitions.find(def => def.name?.value === 'Foo')?.directives;
console.log(directives.length);
console.log(directives.map(dir => dir.arguments[0].value.values.length));
Expected behavior
Console output should be
3
[ 1, 1, 1 ]
but instead it is
1
[ 3 ]
Environment:
- OS: Windows
@graphql-tools/merge: 8.2.6graphql: 16.3.0- NodeJS: v14.17.6
+1 on this we're seeing the same issue.