rishabhjainps
rishabhjainps

Reputation: 500

Graphql query nodes execution order

Lets say we have query -

Node1 {
    Node2
    Node3
}

What will be the execution order here?

I know Node1Resolver will be executed before Node2 and Node3 Resolver, but what about order of Node2, Node3 how will these get executed - parallel or sequentially?

Upvotes: 0

Views: 1419

Answers (1)

Daniel Rearden
Daniel Rearden

Reputation: 84687

From the spec:

Normally the executor can execute the entries in a grouped field set in whatever order it chooses (normally in parallel). Because the resolution of fields other than top‐level mutation fields must always be side effect‐free and idempotent, the execution order must not affect the result, and hence the server has the freedom to execute the field entries in whatever order it deems optimal.

When executing a mutation, the selections in the top most selection set will be executed in serial order, starting with the first appearing field textually.

In other words, because fields on the root mutation type may have side effects, they have to be executed sequentially. For all other fields (including child fields of the former), the order of execution doesn't matter. In practice, most implementations (for example, the reference graphql-js implementation) resolve these fields in parallel.

Upvotes: 2

Related Questions