graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Extending a type with `mergeTypeDefs` throws away the `repeatable` definition on a schema directive

Open magicmark opened this issue 1 year ago • 0 comments

Describe the bug

mergeTypeDefs ignores repeatable...sometimes

To Reproduce Steps to reproduce the behavior:

StackBlitz: https://stackblitz.com/edit/stackblitz-starters-ydtdvx?file=index.mjs

import { mergeTypeDefs } from '@graphql-tools/merge';

const td0 = `directive @foo(person: String) repeatable on OBJECT`;

const td1 = `
  type Foo @foo(person: "alice") @foo(person: "bob"){
    hello: String
  }
`;

const td2 = `
  extend type Foo {
    goodbye: String
  }
`;

console.log(
  'directive count:',
  mergeTypeDefs([td1]).definitions.find(
    (d) => d.kind === 'ObjectTypeDefinition' && d.name.value === 'Foo'
  ).directives.length
); // directive count: 2 ✅

console.log(
  'directive count:',
  mergeTypeDefs([td0, td1, td2]).definitions.find(
    (d) => d.kind === 'ObjectTypeDefinition' && d.name.value === 'Foo'
  ).directives.length
); // directive count: 2 ✅

console.log(
  'directive count:',
  mergeTypeDefs([td1, td2]).definitions.find(
    (d) => d.kind === 'ObjectTypeDefinition' && d.name.value === 'Foo'
  ).directives.length
); // directive count: 1 ❌

Expected behavior

Should be directive count: 2 in all test cases.

Environment:

"@graphql-tools/merge": "9.0.7"

magicmark avatar Sep 09 '24 21:09 magicmark