Skip to content

Commit 17e2a47

Browse files
benjieyaacovCRleebyron
authored
Replace ExecuteSelectionSet with ExecuteCollectedFields (#1039)
* Extract common logic from ExecuteQuery, ExecuteMutation and ExecuteSubscriptionEvent * Change ExecuteSelectionSet to ExecuteGroupedFieldSet * Correct reference to MergeSelectionSets * move Field Collection section earlier (#1111) * Define 'grouped field set' * that -> which * More similar to prior wording * Remove reason from definition * subGroupedFieldSet -> fieldGroupedFieldSet * Add note for clarity * move field collections into one section, section reworking, minor word tweaking, enum * Apply suggestions from code review * Rename 'ExecuteGroupedFieldSet' to 'ExecuteCollectedFields' * Lee editorial + manual merge #1161 * also rename grouped field set -> collected fields map * include changes after merging master * fixup map iterations * editorial --------- Co-authored-by: Yaacov Rydzinski <yaacovCR@gmail.com> Co-authored-by: Lee Byron <lee@leebyron.com>
1 parent e71805e commit 17e2a47

File tree

3 files changed

+286
-218
lines changed

3 files changed

+286
-218
lines changed

spec/Section 3 -- Type System.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,8 @@ type Person {
779779
}
780780
```
781781

782-
Valid operations must supply a nested field set for any field that returns an
783-
object, so this operation is not valid:
782+
Valid operations must supply a _selection set_ for every field of an object
783+
type, so this operation is not valid:
784784

785785
```graphql counter-example
786786
{

spec/Section 5 -- Validation.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -302,24 +302,25 @@ query getName {
302302
- Let {subscriptionType} be the root Subscription type in {schema}.
303303
- For each subscription operation definition {subscription} in the document:
304304
- Let {selectionSet} be the top level selection set on {subscription}.
305-
- Let {groupedFieldSet} be the result of
305+
- Let {collectedFieldsMap} be the result of
306306
{CollectSubscriptionFields(subscriptionType, selectionSet)}.
307-
- {groupedFieldSet} must have exactly one entry, which must not be an
307+
- {collectedFieldsMap} must have exactly one entry, which must not be an
308308
introspection field.
309309

310310
CollectSubscriptionFields(objectType, selectionSet, visitedFragments):
311311

312312
- If {visitedFragments} is not provided, initialize it to the empty set.
313-
- Initialize {groupedFields} to an empty ordered map of lists.
313+
- Initialize {collectedFieldsMap} to an empty ordered map of ordered sets.
314314
- For each {selection} in {selectionSet}:
315315
- {selection} must not provide the `@skip` directive.
316316
- {selection} must not provide the `@include` directive.
317317
- If {selection} is a {Field}:
318-
- Let {responseKey} be the response key of {selection} (the alias if
318+
- Let {responseName} be the _response name_ of {selection} (the alias if
319319
defined, otherwise the field name).
320-
- Let {groupForResponseKey} be the list in {groupedFields} for
321-
{responseKey}; if no such list exists, create it as an empty list.
322-
- Append {selection} to the {groupForResponseKey}.
320+
- Let {fieldsForResponseKey} be the _field set_ value in
321+
{collectedFieldsMap} for the key {responseName}; otherwise create the
322+
entry with an empty ordered set.
323+
- Add {selection} to the {fieldsForResponseKey}.
323324
- If {selection} is a {FragmentSpread}:
324325
- Let {fragmentSpreadName} be the name of {selection}.
325326
- If {fragmentSpreadName} is in {visitedFragments}, continue with the next
@@ -333,31 +334,31 @@ CollectSubscriptionFields(objectType, selectionSet, visitedFragments):
333334
- If {DoesFragmentTypeApply(objectType, fragmentType)} is {false}, continue
334335
with the next {selection} in {selectionSet}.
335336
- Let {fragmentSelectionSet} be the top-level selection set of {fragment}.
336-
- Let {fragmentGroupedFieldSet} be the result of calling
337+
- Let {fragmentCollectedFieldMap} be the result of calling
337338
{CollectSubscriptionFields(objectType, fragmentSelectionSet,
338339
visitedFragments)}.
339-
- For each {fragmentGroup} in {fragmentGroupedFieldSet}:
340-
- Let {responseKey} be the response key shared by all fields in
341-
{fragmentGroup}.
342-
- Let {groupForResponseKey} be the list in {groupedFields} for
343-
{responseKey}; if no such list exists, create it as an empty list.
344-
- Append all items in {fragmentGroup} to {groupForResponseKey}.
340+
- For each {responseName} and {fragmentFields} in
341+
{fragmentCollectedFieldMap}:
342+
- Let {fieldsForResponseKey} be the _field set_ value in
343+
{collectedFieldsMap} for the key {responseName}; otherwise create the
344+
entry with an empty ordered set.
345+
- Add each item from {fragmentFields} to {fieldsForResponseKey}.
345346
- If {selection} is an {InlineFragment}:
346347
- Let {fragmentType} be the type condition on {selection}.
347348
- If {fragmentType} is not {null} and {DoesFragmentTypeApply(objectType,
348349
fragmentType)} is {false}, continue with the next {selection} in
349350
{selectionSet}.
350351
- Let {fragmentSelectionSet} be the top-level selection set of {selection}.
351-
- Let {fragmentGroupedFieldSet} be the result of calling
352+
- Let {fragmentCollectedFieldMap} be the result of calling
352353
{CollectSubscriptionFields(objectType, fragmentSelectionSet,
353354
visitedFragments)}.
354-
- For each {fragmentGroup} in {fragmentGroupedFieldSet}:
355-
- Let {responseKey} be the response key shared by all fields in
356-
{fragmentGroup}.
357-
- Let {groupForResponseKey} be the list in {groupedFields} for
358-
{responseKey}; if no such list exists, create it as an empty list.
359-
- Append all items in {fragmentGroup} to {groupForResponseKey}.
360-
- Return {groupedFields}.
355+
- For each {responseName} and {fragmentFields} in
356+
{fragmentCollectedFieldMap}:
357+
- Let {fieldsForResponseKey} be the _field set_ value in
358+
{collectedFieldsMap} for the key {responseName}; otherwise create the
359+
entry with an empty ordered set.
360+
- Add each item from {fragmentFields} to {fieldsForResponseKey}.
361+
- Return {collectedFieldsMap}.
361362

362363
Note: This algorithm is very similar to {CollectFields()}, it differs in that it
363364
does not have access to runtime variables and thus the `@skip` and `@include`
@@ -583,7 +584,7 @@ should be unambiguous. Therefore any two field selections which might both be
583584
encountered for the same object are only valid if they are equivalent.
584585

585586
During execution, the simultaneous execution of fields with the same response
586-
name is accomplished by {MergeSelectionSets()} and {CollectFields()}.
587+
name is accomplished by {CollectSubfields()} before execution.
587588

588589
For simple hand-written GraphQL, this rule is obviously a clear developer error,
589590
however nested fragments can make this difficult to detect manually.

0 commit comments

Comments
 (0)