Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG codegen incorrectly changes order for persisted operations #9925

Open
wouterpen opened this issue Apr 15, 2024 · 0 comments
Open

BUG codegen incorrectly changes order for persisted operations #9925

wouterpen opened this issue Apr 15, 2024 · 0 comments

Comments

@wouterpen
Copy link

Which packages are impacted by your issue?

@graphql-codegen/client-preset

Describe the bug

https://the-guild.dev/graphql/yoga-server/docs/features/persisted-operations

gives the advise to use https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#persisted-documents

to create our persisted operations. the operation then generates a persisted.document.json like so:

{
"b2c3d4e5f6g7h8i9j0a1": "query Hello { hello }",
"kae4fe7f6g7h8i9ej0ag": "mutation echo($msg: String!) { echo(message: $msg) }"
}

however persistedDocument.js is using printExecutableGraphQLDocument: https://www.npmjs.com/package/@graphql-tools/documents

this sorts all operations alphabetically. But this changes the way mutations work and operations should therefore not be sorted alphabetically see docs: https://spec.graphql.org/October2021/#sec-Mutation

Your Example Website or App

https

Steps to Reproduce the Bug or Issue

create an operation that fires multiple mutations in an order that is not alphabetical
generate trusted documents
see that the order of the mutation in persisted.document.json is different than the original mutations order

Expected behavior

As a user, I expect the order of my mutations to be the same as in my .graphql file so that I can ensure the order in which my mutations are beeing fired. But I am seeing that on generation the order changes.

Screenshots or Videos

mutation x { 
b(test) {
 _id
 }
 a(test) {
 _id
 }
}

results in :

  "kae4fe7f6g7h8i9ej0ag": "mutation x{ a(test){_id} b(test){_id} "

expects:

  "kae4fe7f6g7h8i9ej0ag": "mutation x{ b(test){_id} a(test){_id} "

Platform

  • NodeJS: v20.12.1
  • "@graphql-codegen/client-preset": "4.2.4",

Codegen Config File

'./libs/x/src/lib/': {
preset: 'client',
documents: ['./libs/x/*.graphql'],
presetConfig: {
persistedDocuments: {
hashAlgorithm: 'sha256'
},
},
},

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant