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

@graphql-tools/merge directive arguments compare should not require identical ordering

Open jdolle opened this issue 1 year ago • 0 comments

Issue workflow progress

Progress of the issue based on the Contributor Workflow

  • [x] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox

    Make sure to fork this template and run yarn generate in the terminal.

    Please make sure the GraphQL Tools package versions under package.json matches yours.

  • [x] 2. A failing test has been provided
  • [ ] 3. A local solution has been provided
  • [ ] 4. A pull request is pending review

Describe the bug

Directive merging shouldn't care about argument orders. Arguments are unordered per graphql spec. This is breaking graphql-codegen when two schemas have the same directives but the argument order differs

https://github.com/ardatan/graphql-tools/blob/master/packages/merge/src/typedefs-mergers/directives.ts#L129C3-L132C1

To Reproduce Steps to reproduce the behavior:

const printedNode = "directive @link(url: String!, as: String, import: [link__Import], for: link__Purpose) on SCHEMA"
const printedExistingNode = "directive @link(as: String, for: link__Purpose, import: [link__Import], url: String!) on SCHEMA"
const leaveInputs = new RegExp('(directive @w*d*)|( on .*$)', 'g');
const sameArguments = printedNode.replace(leaveInputs, '') === printedExistingNode.replace(leaveInputs, '');
console.log(sameArguments);
> false

Expected behavior

validateInputs should return instead of throwing because the inputs are identical, except for the order.

Environment:

  • OS: macos -- but not relevant
  • @graphql-tools/merge: 9.0.1
  • NodeJS: 18 -- but not relevant

Additional context

jdolle avatar Jan 24 '24 20:01 jdolle