Skip to content

Commit b76671b

Browse files
committed
Extract common logic from ExecuteQuery, ExecuteMutation and ExecuteSubscriptionEvent
1 parent e546aac commit b76671b

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

spec/Section 6 -- Execution.md

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,8 @@ ExecuteQuery(query, schema, variableValues, initialValue):
134134
- Let {queryType} be the root Query type in {schema}.
135135
- Assert: {queryType} is an Object type.
136136
- Let {selectionSet} be the top level selection set in {query}.
137-
- Let {data} be the result of running {ExecuteSelectionSet(selectionSet,
138-
queryType, initialValue, variableValues)} _normally_ (allowing
139-
parallelization).
140-
- Let {errors} be the list of all _field error_ raised while executing the
141-
selection set.
142-
- Return an unordered map containing {data} and {errors}.
137+
- Return {ExecuteRootSelectionSet(variableValues, initialValue, queryType,
138+
selectionSet)}.
143139

144140
### Mutation
145141

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

165158
### Subscription
166159

@@ -304,12 +297,8 @@ ExecuteSubscriptionEvent(subscription, schema, variableValues, initialValue):
304297
- Let {subscriptionType} be the root Subscription type in {schema}.
305298
- Assert: {subscriptionType} is an Object type.
306299
- Let {selectionSet} be the top level selection set in {subscription}.
307-
- Let {data} be the result of running {ExecuteSelectionSet(selectionSet,
308-
subscriptionType, initialValue, variableValues)} _normally_ (allowing
309-
parallelization).
310-
- Let {errors} be the list of all _field error_ raised while executing the
311-
selection set.
312-
- Return an unordered map containing {data} and {errors}.
300+
- Return {ExecuteRootSelectionSet(variableValues, initialValue,
301+
subscriptionType, selectionSet)}.
313302

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

326315
- Cancel {responseStream}.
327316

317+
## Executing the Root Selection Set
318+
319+
To execute the root selection set, the object value being evaluated and the
320+
object type need to be known, as well as whether it must be executed serially,
321+
or may be executed in parallel.
322+
323+
Executing the root selection set works similarly for queries (parallel),
324+
mutations (serial), and subscriptions (where it is executed for each event in
325+
the underlying Source Stream).
326+
327+
ExecuteRootSelectionSet(variableValues, initialValue, objectType, selectionSet,
328+
serial):
329+
330+
- If {serial} is not provided, initialize it to {false}.
331+
- Let {data} be the result of running {ExecuteSelectionSet(selectionSet,
332+
objectType, initialValue, variableValues)} _serially_ if {serial} is {true},
333+
_normally_ (allowing parallelization) otherwise.
334+
- Let {errors} be the list of all _field error_ raised while executing the
335+
selection set.
336+
- Return an unordered map containing {data} and {errors}.
337+
328338
## Executing Selection Sets
329339

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

0 commit comments

Comments
 (0)