Skip to content

Commit

Permalink
Extract common logic from ExecuteQuery, ExecuteMutation and ExecuteSu…
Browse files Browse the repository at this point in the history
…bscriptionEvent
  • Loading branch information
benjie committed Sep 19, 2024
1 parent e546aac commit b76671b
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions spec/Section 6 -- Execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,8 @@ ExecuteQuery(query, schema, variableValues, initialValue):
- Let {queryType} be the root Query type in {schema}.
- Assert: {queryType} is an Object type.
- Let {selectionSet} be the top level selection set in {query}.
- Let {data} be the result of running {ExecuteSelectionSet(selectionSet,
queryType, initialValue, variableValues)} _normally_ (allowing
parallelization).
- Let {errors} be the list of all _field error_ raised while executing the
selection set.
- Return an unordered map containing {data} and {errors}.
- Return {ExecuteRootSelectionSet(variableValues, initialValue, queryType,
selectionSet)}.

### Mutation

Expand All @@ -156,11 +152,8 @@ ExecuteMutation(mutation, schema, variableValues, initialValue):
- Let {mutationType} be the root Mutation type in {schema}.
- Assert: {mutationType} is an Object type.
- Let {selectionSet} be the top level selection set in {mutation}.
- Let {data} be the result of running {ExecuteSelectionSet(selectionSet,
mutationType, initialValue, variableValues)} _serially_.
- Let {errors} be the list of all _field error_ raised while executing the
selection set.
- Return an unordered map containing {data} and {errors}.
- Return {ExecuteRootSelectionSet(variableValues, initialValue, mutationType,
selectionSet, true)}.

### Subscription

Expand Down Expand Up @@ -304,12 +297,8 @@ ExecuteSubscriptionEvent(subscription, schema, variableValues, initialValue):
- Let {subscriptionType} be the root Subscription type in {schema}.
- Assert: {subscriptionType} is an Object type.
- Let {selectionSet} be the top level selection set in {subscription}.
- Let {data} be the result of running {ExecuteSelectionSet(selectionSet,
subscriptionType, initialValue, variableValues)} _normally_ (allowing
parallelization).
- Let {errors} be the list of all _field error_ raised while executing the
selection set.
- Return an unordered map containing {data} and {errors}.
- Return {ExecuteRootSelectionSet(variableValues, initialValue,
subscriptionType, selectionSet)}.

Note: The {ExecuteSubscriptionEvent()} algorithm is intentionally similar to
{ExecuteQuery()} since this is how each event result is produced.
Expand All @@ -325,6 +314,27 @@ Unsubscribe(responseStream):

- Cancel {responseStream}.

## Executing the Root Selection Set

To execute the root selection set, the object value being evaluated and the
object type need to be known, as well as whether it must be executed serially,
or may be executed in parallel.

Executing the root selection set works similarly for queries (parallel),
mutations (serial), and subscriptions (where it is executed for each event in
the underlying Source Stream).

ExecuteRootSelectionSet(variableValues, initialValue, objectType, selectionSet,
serial):

- If {serial} is not provided, initialize it to {false}.
- Let {data} be the result of running {ExecuteSelectionSet(selectionSet,
objectType, initialValue, variableValues)} _serially_ if {serial} is {true},
_normally_ (allowing parallelization) otherwise.
- Let {errors} be the list of all _field error_ raised while executing the
selection set.
- Return an unordered map containing {data} and {errors}.

## Executing Selection Sets

To execute a _selection set_, the object value being evaluated and the object
Expand Down

0 comments on commit b76671b

Please sign in to comment.