diff --git a/spec/Section 6 -- Execution.md b/spec/Section 6 -- Execution.md index 8f4b25916..563cc8c20 100644 --- a/spec/Section 6 -- Execution.md +++ b/spec/Section 6 -- Execution.md @@ -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. @@ -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): @@ -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 @@ -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