Skip to content

Commit a868d04

Browse files
committed
wip
1 parent 6e91f98 commit a868d04

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

spec/Section 6 -- Execution.md

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,12 @@ ExecuteSelectionSet(selectionSet, objectType, objectValue, variableValues):
340340
- For each {groupedFieldSet} as {responseKey} and {fields}:
341341
- Let {fieldName} be the name of the first entry in {fields}. Note: This value
342342
is unaffected if an alias is used.
343+
- Let {fragmentVariableValues} be the fragment-variables value of the first entry in {fields}.
343344
- Let {fieldType} be the return type defined for the field {fieldName} of
344345
{objectType}.
345346
- If {fieldType} is defined:
346347
- Let {responseValue} be {ExecuteField(objectType, objectValue, fieldType,
347-
fields, variableValues)}.
348+
fields, variableValues, fragmentVariableValues)}.
348349
- Set {responseValue} as the value for {responseKey} in {resultMap}.
349350
- Return {resultMap}.
350351

@@ -492,27 +493,27 @@ The depth-first-search order of the field groups produced by {CollectFields()}
492493
is maintained through execution, ensuring that fields appear in the executed
493494
response in a stable and predictable order.
494495

495-
CollectFields(objectType, selectionSet, variableValues, visitedFragments):
496+
CollectFields(objectType, selectionSet, variableValues, visitedFragments, localVariableValues):
496497

497498
- If {visitedFragments} is not provided, initialize it to the empty set.
498499
- Initialize {groupedFields} to an empty ordered map of lists.
499500
- For each {selection} in {selectionSet}:
500501
- If {selection} provides the directive `@skip`, let {skipDirective} be that
501502
directive.
502503
- If {skipDirective}'s {if} argument is {true} or is a variable in
503-
{variableValues} with the value {true}, continue with the next {selection}
504+
{localVariableValues} or {variableValues} with the value {true}, continue with the next {selection}
504505
in {selectionSet}.
505506
- If {selection} provides the directive `@include`, let {includeDirective} be
506507
that directive.
507508
- If {includeDirective}'s {if} argument is not {true} and is not a variable
508-
in {variableValues} with the value {true}, continue with the next
509+
in {localVariableValues} or {variableValues} with the value {true}, continue with the next
509510
{selection} in {selectionSet}.
510511
- If {selection} is a {Field}:
511512
- Let {responseKey} be the response key of {selection} (the alias if
512513
defined, otherwise the field name).
513514
- Let {groupForResponseKey} be the list in {groupedFields} for
514515
{responseKey}; if no such list exists, create it as an empty list.
515-
- Append {selection} to the {groupForResponseKey}.
516+
- Append {selection} and {localVariableValues} to the {groupForResponseKey}.
516517
- If {selection} is a {FragmentSpread}:
517518
- Let {fragmentSpreadName} be the name of {selection}.
518519
- Let {fragment} be the Fragment in the current Document whose name is
@@ -525,10 +526,8 @@ CollectFields(objectType, selectionSet, variableValues, visitedFragments):
525526
- Let {fragmentType} be the type condition on {fragment}.
526527
- If {DoesFragmentTypeApply(objectType, fragmentType)} is {false}, continue
527528
with the next {selection} in {selectionSet}.
528-
- Let {fragmentWithArgumentSubstitutions} be the result of calling
529-
{SubstituteFragmentArguments(fragment, arguments)}.
530-
- Let {fragmentSelectionSet} be the top-level selection set of
531-
{fragmentWithArgumentSubstitutions}.
529+
- Let {localVariableValues} be the result of calling
530+
{getArgumentValuesFromSpread(fragmentSpread, schema, fragmentDefinition.variableDefinitions, variableValues, localVariableValues)}.
532531
- Let {fragmentGroupedFieldSet} be the result of calling
533532
{CollectFields(objectType, fragmentSelectionSet, variableValues,
534533
visitedFragments)}.
@@ -567,26 +566,25 @@ DoesFragmentTypeApply(objectType, fragmentType):
567566
- If {objectType} is a possible type of {fragmentType}, return {true}
568567
otherwise return {false}.
569568

570-
SubstituteFragmentArguments(fragment, arguments):
569+
getArgumentValuesFromSpread(fragmentSpread, schema, fragmentDefinitionVariableDefinitions, variableValues, fragmentArgumentValues):
571570

572-
- Let {variablesToSubstitute} be initialized to an empty map.
573-
- For each {variableDefinition} in {fragment}:
571+
- Let {coercedValues} be an empty unordered Map.
572+
- For each {variableDefinition} in {fragmentDefinitionVariableDefinitions}:
574573
- Let {variableName} be the name of {variableDefinition}.
575-
- If {variableName} is a key in {arguments}:
576-
- Let {argumentValue} be the value of {variableName} in {arguments}.
577-
- Add {argumentValue} to {variablesToSubstitute} at key {variableName}.
578-
- Otherwise if {variableDefinition} has a default value {defaultValue}:
579-
- Add {defaultValue} to {variablesToSubstitute} at key {variableName}.
580-
- Otherwise:
581-
- Set the key {variableName} in {variableToSubstitute} to a value indicating
582-
the variable is unset.
583-
- Let {substitutedFragment} be a copy of {fragment} where:
584-
- For each {variable} in the selection set of {fragment}:
585-
- Let {variableUsageName} be the name of {variable}.
586-
- If {variableUsageName} is in {variablesToSubstitute}:
587-
- Replace {variable} with the value of {variableUsageName} in
588-
{variablesToSubstitute}.
589-
- Return {substitutedFragment}.
574+
- Let {variableType} be the type of {variableDefinition}.
575+
- Let {defaultValue} be the default value for {variableDefinition}.
576+
- Let {argumentNode} be the node provided in the fragment-spread for {variableName}
577+
- If {argumentNode} isn't present or is null
578+
- If {defaultValue} exists
579+
- Add an entry to {coercedValues} named {argumentName} with the value
580+
{defaultValue}.
581+
- If {variableType} is not-nullable raise a field-error
582+
- Let {hasValue} be {true} if {fragmentArgumentValues} or {variableValues} provides a value for the name
583+
{variableName}.
584+
- If {variableType} is not-nullable and {hasValue} is {false} raise a field-error
585+
- Add an entry to {coercedValues} named {argumentName} with the value
586+
found in {variableValues} or {fragmentArgumentValues}.
587+
- Return {coercedValues}.
590588

591589
Note: The steps in {CollectFields()} evaluating the `@skip` and `@include`
592590
directives may be applied in either order since they apply commutatively.
@@ -605,12 +603,12 @@ coerces any provided argument values, then resolves a value for the field, and
605603
finally completes that value either by recursively executing another selection
606604
set or coercing a scalar value.
607605

608-
ExecuteField(objectType, objectValue, fieldType, fields, variableValues):
606+
ExecuteField(objectType, objectValue, fieldType, fields, variableValues, fragmentVariableValues):
609607

610608
- Let {field} be the first entry in {fields}.
611609
- Let {fieldName} be the field name of {field}.
612610
- Let {argumentValues} be the result of {CoerceFieldArgumentValues(objectType,
613-
field, variableValues)}.
611+
field, variableValues, fragmentVariableValues)}
614612
- Let {resolvedValue} be {ResolveFieldValue(objectType, objectValue, fieldName,
615613
argumentValues)}.
616614
- Return the result of {CompleteValue(fieldType, fields, resolvedValue,
@@ -625,16 +623,16 @@ the type system to have a specific input type.
625623
At each argument position in an operation may be a literal {Value}, or a
626624
{Variable} to be provided at runtime.
627625

628-
CoerceFieldArgumentValues(objectType, field, variableValues):
626+
CoerceFieldArgumentValues(objectType, field, variableValues, fragmentVariableValues):
629627

630628
- Let {argumentValues} be the argument values provided in {field}.
631629
- Let {fieldName} be the name of {field}.
632630
- Let {argumentDefinitions} be the arguments defined by {objectType} for the
633631
field named {fieldName}.
634632
- Return {CoerceArgumentValues(argumentDefinitions, argumentValues,
635-
variableValues)}
633+
variableValues, fragmentVariableValues)}
636634

637-
CoerceArgumentValues(argumentDefinitions, argumentValues, variableValues):
635+
CoerceArgumentValues(argumentDefinitions, argumentValues, variableValues, fragmentVariableValues):
638636

639637
- For each {argumentDefinition} in {argumentDefinitions}:
640638
- Let {argumentName} be the name of {argumentDefinition}.
@@ -646,6 +644,10 @@ CoerceArgumentValues(argumentDefinitions, argumentValues, variableValues):
646644
{argumentName}.
647645
- If {argumentValue} is a {Variable}:
648646
- Let {variableName} be the name of {argumentValue}.
647+
- Let {hasValue} be {true} if {fragmentVariableValues} provides a value for the name
648+
{variableName}.
649+
- Let {value} be the value provided in {fragmentVariableValues} for the name
650+
{variableName}.
649651
- Let {hasValue} be {true} if {variableValues} provides a value for the name
650652
{variableName}.
651653
- Let {value} be the value provided in {variableValues} for the name

0 commit comments

Comments
 (0)