Skip to content

mergeTypeDefs cannot merge two directives if their comments differ #3031

@pranavkevadiya7

Description

@pranavkevadiya7

Describe the bug
mergeTypeDefs from @graphql-tools/merge is failing to merge 2 directives if their comments do not match. More precisely, the comments should not be considered as a DIFF while merging those.

The error is coming from the following code block

const leaveInputs = new RegExp('(directive @w*d*)|( on .*$)', 'g');
    const sameArguments = printedNode.replace(leaveInputs, '') === printedExistingNode.replace(leaveInputs, '');
    if (!sameArguments) {
        throw new Error(`Unable to merge GraphQL directive "${node.name.value}". \nExisting directive:  \n\t${printedExistingNode} \nReceived directive: \n\t${printedNode}`);
    }

To Reproduce
Please run the following test

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

it('Merges 2 schemas together with same directives', () => {
  mergeTypeDefs([
    `
    "Comment"
    directive @canonical on OBJECT | INTERFACE | INPUT_OBJECT | UNION | ENUM | SCALAR | FIELD_DEFINITION | INPUT_FIELD_DEFINITION
    `,
    'directive @canonical on OBJECT | INTERFACE | INPUT_OBJECT | UNION | ENUM | SCALAR | FIELD_DEFINITION | INPUT_FIELD_DEFINITION'
  ])
})

Expected behavior
The merging should not fail and should ignore the comments.

Environment:

  • OS: MacOS
  • @graphql-tools/merge
  • NodeJS: v14.15.2

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    waiting-for-releaseFixed/resolved, and waiting for the next stable release

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions