Skip to content

Commit

Permalink
don't pass in mutable arguments to CollectFields
Browse files Browse the repository at this point in the history
instead, have the caller merge the results
  • Loading branch information
yaacovCR committed Jan 14, 2023
1 parent a8b4273 commit aa2ccb3
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions spec/Section 6 -- Execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,9 @@ The depth-first-search order of the field groups produced by {CollectFields()}
is maintained through execution, ensuring that fields appear in the executed
response in a stable and predictable order.

CollectFields(objectType, selectionSet, variableValues, groupedFieldSet,
visitedFragments):
CollectFields(objectType, selectionSet, variableValues, visitedFragments):

- If {groupedFieldSet} is not provided, initialize it an empty ordered map of
lists.
- If {visitedFragments} is not provided, initialize it to the empty set.
- Initialize {groupedFieldSet} to an empty ordered map of lists.
- For each {selection} in {selectionSet}:
- If {selection} provides the directive `@skip`, let {skipDirective} be that
directive.
Expand Down Expand Up @@ -530,16 +527,31 @@ visitedFragments):
- If {DoesFragmentTypeApply(objectType, fragmentType)} is false, continue
with the next {selection} in {selectionSet}.
- Let {fragmentSelectionSet} be the top-level selection set of {fragment}.
- Call {CollectFields(objectType, fragmentSelectionSet, variableValues,
groupedFieldSet, visitedFragments)}.
- Let {fragmentGroupedFieldSet} be the result of calling
{CollectFields(objectType, fragmentSelectionSet, variableValues,
visitedFragments)}.
- For each {fragmentGroup} in {fragmentGroupedFieldSet}:
- Let {responseKey} be the response key shared by all fields in
{fragmentGroup}.
- Let {groupForResponseKey} be the list in {groupedFieldSet} for
{responseKey}; if no such list exists, create it as an empty list.
- Append all items in {fragmentGroup} to {groupForResponseKey}.
- If {selection} is an {InlineFragment}:
- Let {fragmentType} be the type condition on {selection}.
- If {fragmentType} is not {null} and {DoesFragmentTypeApply(objectType,
fragmentType)} is false, continue with the next {selection} in
{selectionSet}.
- Let {fragmentSelectionSet} be the top-level selection set of {selection}.
- Call {CollectFields(objectType, fragmentSelectionSet, variableValues,
groupedFieldSet, visitedFragments)}.
- Let {fragmentGroupedFieldSet} be the result of calling
{CollectFields(objectType, fragmentSelectionSet, variableValues,
visitedFragments)}.
- For each {fragmentGroup} in {fragmentGroupedFieldSet}:
- Let {responseKey} be the response key shared by all fields in
{fragmentGroup}.
- Let {groupForResponseKey} be the list in {groupedFieldSet} for
{responseKey}; if no such list exists, create it as an empty list.
- Append all items in {fragmentGroup} to {groupForResponseKey}.
- Return {groupedFields} and {visitedFragments}.

DoesFragmentTypeApply(objectType, fragmentType):

Expand All @@ -562,9 +574,9 @@ Root field collection processes the operation's top-level selection set:

CollectRootFields(rootType, operationSelectionSet, variableValues):

- Initialize {groupedFieldSet} to an empty ordered map of lists.
- Call {CollectFields(rootType, operationSelectionSet, variableValues
groupedFieldSet)}.
- Initialize {visitedFragments} to the empty set.
- Let {groupedFieldSet} be the result of calling {CollectFields(rootType,
operationSelectionSet, variableValues, visitedFragments)}.
- Return {groupedFieldSet}.

### Object Subfield Collection
Expand All @@ -573,12 +585,22 @@ Object subfield collection processes a field's sub-selection sets:

CollectSubfields(objectType, fields, variableValues):

- Initialize {visitedFragments} to the empty set.
- Initialize {groupedSubfieldSet} to an empty ordered map of lists.
- For each {field} in {fields}:
- Let {fieldSelectionSet} be the selection set of {field}.
- If {fieldSelectionSet} is null or empty, continue to the next field.
- Call {CollectFields(objectType, fieldSelectionSet, variableValues,
groupedSubfieldSet)}.
- Let {fieldGroupedFieldSet} and {fieldVisitedFragments} be the result of
calling {CollectFields(objectType, fragmentSelectionSet, variableValues,
visitedFragments)}.
- For each {fieldGroup} in {fieldGroupedFieldSet}:
- Let {responseKey} be the response key shared by all fields in
{fragmentGroup}.
- Let {groupForResponseKey} be the list in {groupedFieldSet} for
{responseKey}; if no such list exists, create it as an empty list.
- Append all items in {fieldGroup} to {groupForResponseKey}.
- For each {fragmentSpreadName} in {fieldVisitedFragments}:
- Add {fragmentSpreadName} to {visitedFragments}.
- Return {groupedSubfieldSet}.

## Executing Fields
Expand Down

0 comments on commit aa2ccb3

Please sign in to comment.