Preserve the serialization order for mutations #575
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
I run into a problem when sending multiple mutations in a single request to Hasura server backed with PostgreSQL. The mutation query requires to execute
update
andinsert
operations sequentially in a transaction of PostgreSQL, howeverelm-graphql
is serializing their GraphQL operations into alphabetical order which is the problem.More specifically, with this code we expect the
updateUser
runs first then theinsertUser
.However actually this is serialized to something like follows.
With this query, Hasura issues PostgreSQL query in order of
insert
thenupdate
which will fail in my schema. I think this behavior is counter intuitive and can be a pitfall for users. Also I have searched a bit for another projects and I found this and GraphQL specshttp://spec.graphql.org/October2021/#sec-Normal-and-Serial-Execution
which says the execution order must be in serial for mutations.
The current implementation uses standard
Dict
package for serializing fieldselm-graphql/src/Graphql/Document/Field.elm
Lines 127 to 141 in 0680565
which cause serialization of the fields in alphabetical order.
To prevent this re-ordering, in this PR, I have naively replaced it with j-mass/elm-ordered-containers and it seems to give us the expected result.
Thanks