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

@graphql-tools/documents: Mutations should not be sorted as order matters (mutation fields run in series, one after the other)

Open martyganz opened this issue 1 year ago • 0 comments
trafficstars

Issue workflow progress

Progress of the issue based on the Contributor Workflow

  • [ ] 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
  • [X] 3. A local solution has been provided
  • [X] 4. A pull request is pending review

Describe the bug

printExecutableGraphQLDocument sorts mutations by name whereas from the GraphQL spec the order of mutation matters, they do not run in parallel like queries, but in series. See: https://graphql.org/learn/queries/#multiple-fields-in-mutations

To Reproduce Steps to reproduce the behavior:

packages/documents/tests/print-executable-graphql-document.spec.ts add the following test:

test('should not sort a mutation as mutations run in series and order matters', () => { const inputDocument = parse(/* GraphQL */ mutation A { c { f e d } b a }); const outputStr = printExecutableGraphQLDocument(inputDocument); expect(outputStr).toMatchInlineSnapshot("mutation A { c { f e d } b a }"); });

Expected behavior

Mutations not to be sorted

Environment:

  • OS: MacOS
  • "@graphql-tools/documents@^1.0.0"::
  • NodeJS: LTS Iron (v20) - Now using node v20.12.2 (npm v10.5.0)

Additional context

Linked issue in graphql-code-generator: https://github.com/dotansimha/graphql-code-generator/issues/9925 PR I made to graphql-code-generator to provide an alternative: https://github.com/dotansimha/graphql-code-generator/pull/9926 - here I was asked to create a PR here ;)

Creating a PR here now

martyganz avatar May 17 '24 14:05 martyganz