Normal and Serial Execution

Normally the executor can execute the entries in a grouped field set in whatever order it chooses (often 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.

For example, given the following grouped field set to be executed normally:

{
  birthday {
    month
  }
  address {
    street
  }
}

A valid GraphQL executor can resolve the four fields in whatever order it chose (however of coursebirthdaymust be resolved beforemonth, andaddressbeforestreet).

When executing a mutation, the selections in the top most selection set will be executed in serial order.

When executing a grouped field set serially, the executor must consider each entry from the grouped field set in the order provided in the grouped field set. It must determine the corresponding entry in the result map for each item to completion before it continues on to the next item in the grouped field set:

For example, given the following selection set to be executed serially:

{
  changeBirthday(birthday: $newBirthday) {
    month
  }
  changeAddress(address: $newAddress) {
    street
  }
}

The executor must, in serial:

  • Run ExecuteField () for changeBirthday , which during CompleteValue () will execute the { month } sub‐selection set normally.
  • Run ExecuteField () for changeAddress , which during CompleteValue () will execute the { street } sub‐selection set normally.

As an illustrative example, let’s assume we have a mutation fieldchangeTheNumberthat returns an object containing one field,theNumber. If we execute the following selection set serially:

{
  first: changeTheNumber(newNumber: 1) {
    theNumber
  }
  second: changeTheNumber(newNumber: 3) {
    theNumber
  }
  third: changeTheNumber(newNumber: 2) {
    theNumber
  }
}

The executor will execute the following serially:

  • Resolve the changeTheNumber(newNumber: 1) field
  • Execute the { theNumber } sub‐selection set of first normally
  • Resolve the changeTheNumber(newNumber: 3) field
  • Execute the { theNumber } sub‐selection set of second normally
  • Resolve the changeTheNumber(newNumber: 2) field
  • Execute the { theNumber } sub‐selection set of third normally

A correct executor must generate the following result for that selection set:

{

"first"
: {

"theNumber"
: 
1

  },

"second"
: {

"theNumber"
: 
3

  },

"third"
: {

"theNumber"
: 
2

  }
}

results matching ""

    No results matching ""