Skip to content

Commit 3c78d84

Browse files
benjieyaacovCR
authored andcommitted
Extract common logic from ExecuteQuery, ExecuteMutation and ExecuteSubscriptionEvent
1 parent feac5a5 commit 3c78d84

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

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

310299
Note: The {ExecuteSubscriptionEvent()} algorithm is intentionally similar to
311300
{ExecuteQuery()} since this is how each event result is produced.
@@ -321,6 +310,27 @@ Unsubscribe(responseStream):
321310

322311
- Cancel {responseStream}
323312

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

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

0 commit comments

Comments
 (0)