Skip to content

Commit 969f692

Browse files
committed
formatting and expand examples
1 parent 3bc4e59 commit 969f692

File tree

3 files changed

+62
-39
lines changed

3 files changed

+62
-39
lines changed

spec/Section 2 -- Language.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,12 +1216,13 @@ size `60`:
12161216
**Variable Use Within Fragments**
12171217

12181218
Variables can be used within fragments. Operation-defined variables have global
1219-
scope within a given operation. Fragment-defined variables have local scope within the
1220-
fragment definition in which they are defined. A variable used within a fragment must either
1221-
be declared in each top-level operation that transitively consumes that fragment,
1222-
or by that same fragment as a fragment variable definition. If a variable
1223-
referenced in a fragment is included by an operation where neither the fragment
1224-
nor the operation defines that variable, that operation is invalid (see
1219+
scope within a given operation. Fragment-defined variables have local scope
1220+
within the fragment definition in which they are defined. A variable used within
1221+
a fragment must either be declared in each top-level operation that transitively
1222+
consumes that fragment, or by that same fragment as a fragment variable
1223+
definition. If a variable referenced in a fragment is included by an operation
1224+
where neither the fragment nor the operation defines that variable, that
1225+
operation is invalid (see
12251226
[All Variable Uses Defined](#sec-All-Variable-Uses-Defined)).
12261227

12271228
## Fragment Variable Definitions
@@ -1275,10 +1276,10 @@ fragment dynamicProfilePic($size: Int!) on User {
12751276
```
12761277

12771278
The profilePic for `user` will be determined by the variables set by the
1278-
operation, while `secondUser` will always have a `profilePic` of size `10`. In this
1279-
case, the fragment `variableProfilePic` uses the operation-defined variable,
1280-
while `dynamicProfilePic` uses the value passed in via the fragment spread's
1281-
`size` argument.
1279+
operation, while `secondUser` will always have a `profilePic` of size `10`. In
1280+
this case, the fragment `variableProfilePic` uses the operation-defined
1281+
variable, while `dynamicProfilePic` uses the value passed in via the fragment
1282+
spread's `size` argument.
12821283

12831284
## Type References
12841285

spec/Section 5 -- Validation.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,10 @@ FieldsInSetCanMerge(set):
424424
- Let {spreadsForName} be the set of fragment spreads with a given name in
425425
{visitedSelections}.
426426
- For each {spreadsForName} as {name} and {spreads}:
427-
- Each entry in {spreads} must have identical sets of arguments to each other entry in {spreads}.
428-
- Let {fieldsForName} be the set of field selections with a given response name in
429-
{visitedSelections}.
427+
- Each entry in {spreads} must have identical sets of arguments to each other
428+
entry in {spreads}.
429+
- Let {fieldsForName} be the set of field selections with a given response name
430+
in {visitedSelections}.
430431
- Given each pair of members {fieldA} and {fieldB} in {fieldsForName}:
431432
- {SameResponseShape(fieldA, fieldB)} must be true.
432433
- If the parent types of {fieldA} and {fieldB} are equal or if either is not
@@ -602,8 +603,9 @@ the fragment spread `...commandFragment(command: SIT)` and
602603
`...commandFragment(command: DOWN)` are part of the visited selections that will
603604
be merged.
604605

605-
If both of these spreads would have `$commandOne` or `$commandTwo` as the argument-value,
606-
it would be allowed as we can be sure that we'd resolve identical fields.
606+
If both of these spreads would have `$commandOne` or `$commandTwo` as the
607+
argument-value, it would be allowed as we can be sure that we'd resolve
608+
identical fields.
607609

608610
### Leaf Field Selections
609611

@@ -699,8 +701,8 @@ validation rules apply in each case.
699701

700702
**Explanatory Text**
701703

702-
Every argument provided to a field or directive or fragment spread must be
703-
defined in the set of possible arguments of that field, directive or fragment.
704+
Every argument provided to a field or directive must be defined in the set of
705+
possible arguments of that field or directive.
704706

705707
For example the following are valid:
706708

@@ -712,7 +714,13 @@ fragment argOnRequiredArg on Dog {
712714
fragment argOnOptional on Dog {
713715
isHouseTrained(atOtherHomes: true) @include(if: true)
714716
}
717+
```
715718

719+
The above is also applicable to fragment-definitions and fragment-spreads, each
720+
variable must be defined by the fragment-definition before it can be inserted as
721+
an argument by the fragment-spread.
722+
723+
```graphql example
716724
fragment withFragmentArg($command: DogCommand) on Dog {
717725
doesKnowCommand(dogCommand: $command)
718726
}
@@ -738,6 +746,10 @@ and this is also invalid as the argument `dogCommand` is not defined on fragment
738746
fragment invalidFragmentArgName on Dog {
739747
...withFragmentArg(dogCommand: SIT)
740748
}
749+
750+
fragment withFragmentArg($command: DogCommand) on Dog {
751+
doesKnowCommand(dogCommand: $command)
752+
}
741753
```
742754

743755
and this is also invalid as `unless` is not defined on `@include`.
@@ -1620,8 +1632,8 @@ fragment HouseTrainedFragment on Query {
16201632
}
16211633
```
16221634

1623-
Likewise, it is valid for a fragment to define a variable with a name that
1624-
is also defined on an operation:
1635+
Likewise, it is valid for a fragment to define a variable with a name that is
1636+
also defined on an operation:
16251637

16261638
```graphql example
16271639
query C($atOtherHomes: Boolean) {
@@ -1989,7 +2001,8 @@ fragment fragmentArgUnused($atOtherHomes: Boolean) on Dog {
19892001
}
19902002
```
19912003

1992-
This document is invalid: fragment `fragmentArgUnused` defines a fragment variable `$atOtherHomes`, but this variable is not used within this fragment.
2004+
This document is invalid: fragment `fragmentArgUnused` defines a fragment
2005+
variable `$atOtherHomes`, but this variable is not used within this fragment.
19932006

19942007
### All Variable Usages Are Allowed
19952008

spec/Section 6 -- Execution.md

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ 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}.
343+
- Let {fragmentVariableValues} be the fragment-variables value of the first
344+
entry in {fields}.
344345
- Let {fieldType} be the return type defined for the field {fieldName} of
345346
{objectType}.
346347
- If {fieldType} is defined:
@@ -491,21 +492,22 @@ The depth-first-search order of the field groups produced by {CollectFields()}
491492
is maintained through execution, ensuring that fields appear in the executed
492493
response in a stable and predictable order.
493494

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

496498
- If {visitedFragments} is not provided, initialize it to the empty set.
497499
- Initialize {groupedFields} to an empty ordered map of lists.
498500
- For each {selection} in {selectionSet}:
499501
- If {selection} provides the directive `@skip`, let {skipDirective} be that
500502
directive.
501503
- If {skipDirective}'s {if} argument is {true} or is a variable in
502-
{localVariableValues} or {variableValues} with the value {true}, continue with the next {selection}
503-
in {selectionSet}.
504+
{localVariableValues} or {variableValues} with the value {true}, continue
505+
with the next {selection} in {selectionSet}.
504506
- If {selection} provides the directive `@include`, let {includeDirective} be
505507
that directive.
506508
- If {includeDirective}'s {if} argument is not {true} and is not a variable
507-
in {localVariableValues} or {variableValues} with the value {true}, continue with the next
508-
{selection} in {selectionSet}.
509+
in {localVariableValues} or {variableValues} with the value {true},
510+
continue with the next {selection} in {selectionSet}.
509511
- If {selection} is a {Field}:
510512
- Let {responseKey} be the response key of {selection} (the alias if
511513
defined, otherwise the field name).
@@ -525,7 +527,8 @@ CollectFields(objectType, selectionSet, variableValues, visitedFragments, localV
525527
- If {DoesFragmentTypeApply(objectType, fragmentType)} is {false}, continue
526528
with the next {selection} in {selectionSet}.
527529
- Let {localVariableValues} be the result of calling
528-
{getArgumentValuesFromSpread(selection, fragmentDefinition, variableValues, localVariableValues)}.
530+
{getArgumentValuesFromSpread(selection, fragmentDefinition,
531+
variableValues, localVariableValues)}.
529532
- Let {fragmentGroupedFieldSet} be the result of calling
530533
{CollectFields(objectType, fragmentSelectionSet, variableValues,
531534
visitedFragments)}.
@@ -564,24 +567,27 @@ DoesFragmentTypeApply(objectType, fragmentType):
564567
- If {objectType} is a possible type of {fragmentType}, return {true}
565568
otherwise return {false}.
566569

567-
getArgumentValuesFromSpread(fragmentSpread, fragmentDefinition, variableValues, fragmentArgumentValues):
570+
getArgumentValuesFromSpread(fragmentSpread, fragmentDefinition, variableValues,
571+
fragmentArgumentValues):
568572

569573
- Let {coercedValues} be an empty unordered Map.
570574
- For each {variableDefinition} in {fragmentDefinition}:
571575
- Let {variableName} be the name of {variableDefinition}.
572576
- Let {variableType} be the type of {variableDefinition}.
573577
- Let {defaultValue} be the default value for {variableDefinition}.
574-
- Let {argumentNode} be the node provided in the fragment-spread for {variableName}
578+
- Let {argumentNode} be the node provided in the fragment-spread for
579+
{variableName}
575580
- If {argumentNode} isn't present or is null
576581
- If {defaultValue} exists
577582
- Add an entry to {coercedValues} named {argumentName} with the value
578583
{defaultValue}.
579584
- If {variableType} is non-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 non-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+
- Let {hasValue} be {true} if {fragmentArgumentValues} or {variableValues}
586+
provides a value for the name {variableName}.
587+
- If {variableType} is non-nullable and {hasValue} is {false} raise a
588+
field-error
589+
- Add an entry to {coercedValues} named {argumentName} with the value found in
590+
{variableValues} or {fragmentArgumentValues}.
585591
- Return {coercedValues}.
586592

587593
Note: The steps in {CollectFields()} evaluating the `@skip` and `@include`
@@ -595,7 +601,8 @@ coerces any provided argument values, then resolves a value for the field, and
595601
finally completes that value either by recursively executing another selection
596602
set or coercing a scalar value.
597603

598-
ExecuteField(objectType, objectValue, fieldType, fields, variableValues, fragmentVariableValues):
604+
ExecuteField(objectType, objectValue, fieldType, fields, variableValues,
605+
fragmentVariableValues):
599606

600607
- Let {field} be the first entry in {fields}.
601608
- Let {fieldName} be the field name of {field}.
@@ -615,7 +622,8 @@ the type system to have a specific input type.
615622
At each argument position in an operation may be a literal {Value}, or a
616623
{Variable} to be provided at runtime.
617624

618-
CoerceFieldArgumentValues(objectType, field, variableValues, fragmentVariableValues):
625+
CoerceFieldArgumentValues(objectType, field, variableValues,
626+
fragmentVariableValues):
619627

620628
- Let {argumentValues} be the argument values provided in {field}.
621629
- Let {fieldName} be the name of {field}.
@@ -624,7 +632,8 @@ CoerceFieldArgumentValues(objectType, field, variableValues, fragmentVariableVal
624632
- Return {CoerceArgumentValues(argumentDefinitions, argumentValues,
625633
variableValues, fragmentVariableValues)}
626634

627-
CoerceArgumentValues(argumentDefinitions, argumentValues, variableValues, fragmentVariableValues):
635+
CoerceArgumentValues(argumentDefinitions, argumentValues, variableValues,
636+
fragmentVariableValues):
628637

629638
- For each {argumentDefinition} in {argumentDefinitions}:
630639
- Let {argumentName} be the name of {argumentDefinition}.
@@ -636,8 +645,8 @@ CoerceArgumentValues(argumentDefinitions, argumentValues, variableValues, fragme
636645
{argumentName}.
637646
- If {argumentValue} is a {Variable}:
638647
- Let {variableName} be the name of {argumentValue}.
639-
- Let {hasValue} be {true} if {fragmentVariableValues} provides a value for the name
640-
{variableName}.
648+
- Let {hasValue} be {true} if {fragmentVariableValues} provides a value for
649+
the name {variableName}.
641650
- Let {value} be the value provided in {fragmentVariableValues} for the name
642651
{variableName}.
643652
- Let {hasValue} be {true} if {variableValues} provides a value for the name

0 commit comments

Comments
 (0)