GraphQL icon indicating copy to clipboard operation
GraphQL copied to clipboard

Top level fields in mutations should execute in SERIES not parallel

Open cshadek opened this issue 4 years ago • 1 comments

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} ) {
       ....
    }
}

cshadek avatar Jul 16 '21 22:07 cshadek

@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 avatar Sep 08 '21 05:09 NeedleInAJayStack

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

NeedleInAJayStack avatar Apr 12 '23 21:04 NeedleInAJayStack