dotansimha / dotansimha/graphql-code-generator

BUG codegen incorrectly changes order for persisted operations

Open
#9,925 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### 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

```javascript

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

results in :
```javascript
"kae4fe7f6g7h8i9ej0ag": "mutation x{ a(test){_id} b(test){_id} "
```

expects:
```javascript
"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_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.