@@ -110,8 +110,10 @@ CoerceVariableValues(schema, operation, variableValues):
110
110
- Let {value} be the value provided in {variableValues} for the name
111
111
{variableName}.
112
112
- If {hasValue} is not {true} and {defaultValue} exists (including {null}):
113
+ - Let {coercedDefaultValue} be the result of coercing {defaultValue}
114
+ according to the input coercion rules of {variableType}.
113
115
- Add an entry to {coercedValues} named {variableName} with the value
114
- {defaultValue }.
116
+ {coercedDefaultValue }.
115
117
- Otherwise if {variableType} is a Non-Nullable type, and either {hasValue} is
116
118
not {true} or {value} is {null}, raise a _ request error_ .
117
119
- Otherwise if {hasValue} is {true}:
@@ -367,9 +369,9 @@ continues until there are no more subfields to collect and execute.
367
369
operation. A root selection set always selects from a _ root operation type_ .
368
370
369
371
To execute the root selection set, the initial value being evaluated and the
370
- root type must be known, as well as whether each field must be executed
371
- serially , or normally by executing all fields in parallel (see
372
- [ Normal and Serial Execution] ( #sec-Normal-and-Serial-Execution ) .
372
+ root type must be known, as well as whether the fields must be executed in a
373
+ series , or normally by executing all fields in parallel (see
374
+ [ Normal and Serial Execution] ( #sec-Normal-and-Serial-Execution ) ) .
373
375
374
376
Executing the root selection set works similarly for queries (parallel),
375
377
mutations (serial), and subscriptions (where it is executed for each event in
@@ -394,10 +396,9 @@ executionMode):
394
396
### Field Collection
395
397
396
398
Before execution, each _ selection set_ is converted to a _ collected fields map_
397
- by calling {CollectFields()} by collecting all fields with the same response
398
- name, including those in referenced fragments, into an individual _ field set_ .
399
- This ensures that multiple references to fields with the same response name will
400
- only be executed once.
399
+ by collecting all fields with the same response name, including those in
400
+ referenced fragments, into an individual _ field set_ . This ensures that multiple
401
+ references to fields with the same response name will only be executed once.
401
402
402
403
:: A _ collected fields map_ is an ordered map where each entry is a _ response
403
404
name_ and its associated _ field set_ . A _ collected fields map_ may be produced
@@ -434,8 +435,8 @@ fragment ExampleFragment on Query {
434
435
}
435
436
```
436
437
437
- The depth-first-search order of the _ field set_ produced by {CollectFields()} is
438
- maintained through execution, ensuring that fields appear in the executed
438
+ The depth-first-search order of each _ field set_ produced by {CollectFields()}
439
+ is maintained through execution, ensuring that fields appear in the executed
439
440
response in a stable and predictable order.
440
441
441
442
CollectFields(objectType, selectionSet, variableValues, visitedFragments):
@@ -473,11 +474,11 @@ CollectFields(objectType, selectionSet, variableValues, visitedFragments):
473
474
- If {DoesFragmentTypeApply(objectType, fragmentType)} is {false}, continue
474
475
with the next {selection} in {selectionSet}.
475
476
- Let {fragmentSelectionSet} be the top-level selection set of {fragment}.
476
- - Let {fragmentCollectedFieldMap } be the result of calling
477
+ - Let {fragmentCollectedFieldsMap } be the result of calling
477
478
{CollectFields(objectType, fragmentSelectionSet, variableValues,
478
479
visitedFragments)}.
479
480
- For each {responseName} and {fragmentFields} in
480
- {fragmentCollectedFieldMap }:
481
+ {fragmentCollectedFieldsMap }:
481
482
- Let {fieldsForResponseName} be the _ field set_ value in
482
483
{collectedFieldsMap} for the key {responseName}; otherwise create the
483
484
entry with an empty ordered set.
@@ -488,11 +489,11 @@ CollectFields(objectType, selectionSet, variableValues, visitedFragments):
488
489
fragmentType)} is {false}, continue with the next {selection} in
489
490
{selectionSet}.
490
491
- Let {fragmentSelectionSet} be the top-level selection set of {selection}.
491
- - Let {fragmentCollectedFieldMap } be the result of calling
492
+ - Let {fragmentCollectedFieldsMap } be the result of calling
492
493
{CollectFields(objectType, fragmentSelectionSet, variableValues,
493
494
visitedFragments)}.
494
495
- For each {responseName} and {fragmentFields} in
495
- {fragmentCollectedFieldMap }:
496
+ {fragmentCollectedFieldsMap }:
496
497
- Let {fieldsForResponseName} be the _ field set_ value in
497
498
{collectedFieldsMap} for the key {responseName}; otherwise create the
498
499
entry with an empty ordered set.
@@ -516,8 +517,8 @@ directives may be applied in either order since they apply commutatively.
516
517
517
518
** Merging Selection Sets**
518
519
519
- In order to execute the sub-selections of a object typed field, all _ selection
520
- sets_ of each field with the same response name of the parent _ field set_ are
520
+ In order to execute the sub-selections of an object typed field, all _ selection
521
+ sets_ of each field with the same response name in the parent _ field set_ are
521
522
merged together into a single _ collected fields map_ representing the subfields
522
523
to be executed next.
523
524
@@ -552,9 +553,9 @@ CollectSubfields(objectType, fields, variableValues):
552
553
- For each {field} in {fields}:
553
554
- Let {fieldSelectionSet} be the selection set of {field}.
554
555
- If {fieldSelectionSet} is null or empty, continue to the next field.
555
- - Let {fieldCollectedFieldMap } be the result of {CollectFields(objectType,
556
+ - Let {fieldCollectedFieldsMap } be the result of {CollectFields(objectType,
556
557
fieldSelectionSet, variableValues)}.
557
- - For each {responseName} and {subfields} in {fieldCollectedFieldMap }:
558
+ - For each {responseName} and {subfields} in {fieldCollectedFieldsMap }:
558
559
- Let {fieldsForResponseName} be the _ field set_ value in
559
560
{collectedFieldsMap} for the key {responseName}; otherwise create the
560
561
entry with an empty ordered set.
@@ -749,20 +750,22 @@ CoerceArgumentValues(objectType, field, variableValues):
749
750
- Let {argumentName} be the name of {argumentDefinition}.
750
751
- Let {argumentType} be the expected type of {argumentDefinition}.
751
752
- Let {defaultValue} be the default value for {argumentDefinition}.
752
- - Let {hasValue} be {true} if {argumentValues} provides a value for the name
753
- {argumentName}.
754
753
- Let {argumentValue} be the value provided in {argumentValues} for the name
755
754
{argumentName}.
756
755
- If {argumentValue} is a {Variable}:
757
756
- Let {variableName} be the name of {argumentValue}.
758
- - Let {hasValue} be {true} if {variableValues} provides a value for the name
759
- {variableName}.
760
- - Let {value} be the value provided in {variableValues} for the name
761
- {variableName}.
762
- - Otherwise, let {value} be {argumentValue}.
757
+ - If {variableValues} provides a value for the name {variableName}:
758
+ - Let {hasValue} be {true}.
759
+ - Let {value} be the value provided in {variableValues} for the name
760
+ {variableName}.
761
+ - Otherwise if {argumentValues} provides a value for the name {argumentName}.
762
+ - Let {hasValue} be {true}.
763
+ - Let {value} be {argumentValue}.
763
764
- If {hasValue} is not {true} and {defaultValue} exists (including {null}):
765
+ - Let {coercedDefaultValue} be the result of coercing {defaultValue}
766
+ according to the input coercion rules of {argumentType}.
764
767
- Add an entry to {coercedValues} named {argumentName} with the value
765
- {defaultValue }.
768
+ {coercedDefaultValue }.
766
769
- Otherwise if {argumentType} is a Non-Nullable type, and either {hasValue} is
767
770
not {true} or {value} is {null}, raise an _ execution error_ .
768
771
- Otherwise if {hasValue} is {true}:
@@ -788,6 +791,9 @@ Note: Variable values are not coerced because they are expected to be coerced
788
791
before executing the operation in {CoerceVariableValues()}, and valid operations
789
792
must only allow usage of variables of appropriate types.
790
793
794
+ Note: Implementations are encouraged to optimize the coercion of an argument's
795
+ default value by doing so only once and caching the resulting coerced value.
796
+
791
797
### Value Resolution
792
798
793
799
While nearly all of GraphQL execution can be described generically, ultimately
0 commit comments