Skip to content

Commit d12884e

Browse files
committed
Extract common logic from ExecuteQuery, ExecuteMutation and ExecuteSubscriptionEvent
1 parent afc0a35 commit d12884e

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
@@ -131,12 +131,8 @@ ExecuteQuery(query, schema, variableValues, initialValue):
131131
- Let {queryType} be the root Query type in {schema}.
132132
- Assert: {queryType} is an Object type.
133133
- Let {selectionSet} be the top level Selection Set in {query}.
134-
- Let {data} be the result of running {ExecuteSelectionSet(selectionSet,
135-
queryType, initialValue, variableValues)} _normally_ (allowing
136-
parallelization).
137-
- Let {errors} be the list of all _field error_ raised while executing the
138-
selection set.
139-
- Return an unordered map containing {data} and {errors}.
134+
- Return {ExecuteRootSelectionSet(variableValues, initialValue, queryType,
135+
selectionSet)}.
140136

141137
### Mutation
142138

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

162155
### Subscription
163156

@@ -301,12 +294,8 @@ ExecuteSubscriptionEvent(subscription, schema, variableValues, initialValue):
301294
- Let {subscriptionType} be the root Subscription type in {schema}.
302295
- Assert: {subscriptionType} is an Object type.
303296
- Let {selectionSet} be the top level Selection Set in {subscription}.
304-
- Let {data} be the result of running {ExecuteSelectionSet(selectionSet,
305-
subscriptionType, initialValue, variableValues)} _normally_ (allowing
306-
parallelization).
307-
- Let {errors} be the list of all _field error_ raised while executing the
308-
selection set.
309-
- Return an unordered map containing {data} and {errors}.
297+
- Return {ExecuteRootSelectionSet(variableValues, initialValue,
298+
subscriptionType, selectionSet)}.
310299

311300
Note: The {ExecuteSubscriptionEvent()} algorithm is intentionally similar to
312301
{ExecuteQuery()} since this is how each event result is produced.
@@ -322,6 +311,27 @@ Unsubscribe(responseStream):
322311

323312
- Cancel {responseStream}
324313

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

327337
To execute a selection set, the object value being evaluated and the object type

0 commit comments

Comments
 (0)