Skip to content

Commit 08d3d32

Browse files
committed
wip
1 parent 76011b0 commit 08d3d32

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

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

493-
CollectFields(objectType, selectionSet, variableValues, visitedFragments):
494+
CollectFields(objectType, selectionSet, variableValues, visitedFragments, localVariableValues):
494495

495496
- If {visitedFragments} is not provided, initialize it to the empty set.
496497
- Initialize {groupedFields} to an empty ordered map of lists.
497498
- For each {selection} in {selectionSet}:
498499
- If {selection} provides the directive `@skip`, let {skipDirective} be that
499500
directive.
500501
- If {skipDirective}'s {if} argument is {true} or is a variable in
501-
{variableValues} with the value {true}, continue with the next {selection}
502+
{localVariableValues} or {variableValues} with the value {true}, continue with the next {selection}
502503
in {selectionSet}.
503504
- If {selection} provides the directive `@include`, let {includeDirective} be
504505
that directive.
505506
- If {includeDirective}'s {if} argument is not {true} and is not a variable
506-
in {variableValues} with the value {true}, continue with the next
507+
in {localVariableValues} or {variableValues} with the value {true}, continue with the next
507508
{selection} in {selectionSet}.
508509
- If {selection} is a {Field}:
509510
- Let {responseKey} be the response key of {selection} (the alias if
510511
defined, otherwise the field name).
511512
- Let {groupForResponseKey} be the list in {groupedFields} for
512513
{responseKey}; if no such list exists, create it as an empty list.
513-
- Append {selection} to the {groupForResponseKey}.
514+
- Append {selection} and {localVariableValues} to the {groupForResponseKey}.
514515
- If {selection} is a {FragmentSpread}:
515516
- Let {fragmentSpreadName} be the name of {selection}.
516517
- Let {fragment} be the Fragment in the current Document whose name is
@@ -523,10 +524,8 @@ CollectFields(objectType, selectionSet, variableValues, visitedFragments):
523524
- Let {fragmentType} be the type condition on {fragment}.
524525
- If {DoesFragmentTypeApply(objectType, fragmentType)} is {false}, continue
525526
with the next {selection} in {selectionSet}.
526-
- Let {fragmentWithArgumentSubstitutions} be the result of calling
527-
{SubstituteFragmentArguments(fragment, arguments)}.
528-
- Let {fragmentSelectionSet} be the top-level selection set of
529-
{fragmentWithArgumentSubstitutions}.
527+
- Let {localVariableValues} be the result of calling
528+
{getArgumentValuesFromSpread(fragmentSpread, schema, fragmentDefinition.variableDefinitions, variableValues, localVariableValues)}.
530529
- Let {fragmentGroupedFieldSet} be the result of calling
531530
{CollectFields(objectType, fragmentSelectionSet, variableValues,
532531
visitedFragments)}.
@@ -565,26 +564,25 @@ DoesFragmentTypeApply(objectType, fragmentType):
565564
- If {objectType} is a possible type of {fragmentType}, return {true}
566565
otherwise return {false}.
567566

568-
SubstituteFragmentArguments(fragment, arguments):
567+
getArgumentValuesFromSpread(fragmentSpread, schema, fragmentDefinitionVariableDefinitions, variableValues, fragmentArgumentValues):
569568

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

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

606-
ExecuteField(objectType, objectValue, fieldType, fields, variableValues):
604+
ExecuteField(objectType, objectValue, fieldType, fields, variableValues, fragmentVariableValues):
607605

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

626-
CoerceFieldArgumentValues(objectType, field, variableValues):
624+
CoerceFieldArgumentValues(objectType, field, variableValues, fragmentVariableValues):
627625

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

635-
CoerceArgumentValues(argumentDefinitions, argumentValues, variableValues):
633+
CoerceArgumentValues(argumentDefinitions, argumentValues, variableValues, fragmentVariableValues):
636634

637635
- For each {argumentDefinition} in {argumentDefinitions}:
638636
- Let {argumentName} be the name of {argumentDefinition}.
@@ -644,6 +642,10 @@ CoerceArgumentValues(argumentDefinitions, argumentValues, variableValues):
644642
{argumentName}.
645643
- If {argumentValue} is a {Variable}:
646644
- Let {variableName} be the name of {argumentValue}.
645+
- Let {hasValue} be {true} if {fragmentVariableValues} provides a value for the name
646+
{variableName}.
647+
- Let {value} be the value provided in {fragmentVariableValues} for the name
648+
{variableName}.
647649
- Let {hasValue} be {true} if {variableValues} provides a value for the name
648650
{variableName}.
649651
- Let {value} be the value provided in {variableValues} for the name

0 commit comments

Comments
 (0)