GraphQLSwift / GraphQL

The Swift GraphQL implementation for macOS and Linux
MIT License
938 stars 72 forks source link

Top level fields in mutations should execute in SERIES not parallel #86

Closed cshadek closed 1 year ago

cshadek commented 3 years ago

The GraphQL spec specifies that the top level fields in mutations should execute serially.

http://spec.graphql.org/June2018/#sec-Mutation

When I run a Mutation like the following using Graphiti, I get race conditions and unexpected results. The only explanation I have for this is that they are running in parallel. Am I missing something? Thanks!

mutation Test {
    addLike(input: {id: 1}) {
       ....
    }
    removeLike(input: {id: 1} ) {
       ....
    }
    addLike2: addLike(input: {id: 1} ) {
       ....
    }
}
NeedleInAJayStack commented 3 years ago

@cshadek Could you provide a more fleshed-out code example that displays the race conditions and unexpected results?

I did some initial testing and was unable to create the data races/unexpected results you describe. The "like" was always added, removed, and then added again without any ID conflict.

Note that while the top-level mutations execute in series, the GraphQL resolution pattern (concurrent or serial) is always outer-to-inner, so the .... field resolvers are not guaranteed to run before the next mutation occurs. The spec reflects this by specifying that only the top level selection set of the mutation is run serially.

NeedleInAJayStack commented 1 year ago

Resolved by https://github.com/GraphQLSwift/GraphQL/pull/124