Skip to content

Repeatable directives from extensions merged incorrectly #4338

@andreasdamm

Description

@andreasdamm

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.6
  • graphql: 16.3.0
  • NodeJS: v14.17.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions