@@ -419,7 +419,7 @@ fragment directFieldSelectionOnUnion on CatOrDog {
419
419
FieldsInSetCanMerge(set):
420
420
421
421
- Let {visitedSelections} be the selections in {set} including visiting
422
- fragments and inline fragments an applying any supplied fragment arguments.
422
+ fragments and inline fragments and applying any supplied fragment spread arguments.
423
423
- Let {spreadsForName} be the set of fragment spreads with a given name in
424
424
{visitedSelections}.
425
425
- Given each pair of members {spreadA} and {spreadB} in {spreadsForName}:
@@ -576,7 +576,7 @@ fragment conflictingDifferingResponses on Pet {
576
576
}
577
577
```
578
578
579
- Fragment arguments can also cause fields to fail to merge.
579
+ Fragment spread arguments can also cause fields to fail to merge.
580
580
581
581
While the following is valid:
582
582
@@ -599,11 +599,11 @@ fragment safeFragmentArguments on Dog {
599
599
```
600
600
601
601
it is only valid because ` safeFragmentArguments ` uses
602
- ` potentiallyConflictingArguments ` with the same value for ` commandOne ` and
602
+ ` potentiallyConflictingArguments ` with the same value for the fragment-defined variables ` commandOne ` and
603
603
` commandTwo ` . Therefore ` commandFragment ` resolves ` doesKnowCommand ` 's
604
- ` dogCommand: ` arg to ` SIT ` in both cases.
604
+ ` dogCommand ` argument value to ` SIT ` in both cases.
605
605
606
- However, by changing the argument values:
606
+ However, by changing the fragment spread argument values:
607
607
608
608
``` graphql counter-example
609
609
fragment conflictingFragmentArguments on Dog {
@@ -706,14 +706,15 @@ validation rules apply in each case.
706
706
707
707
- For each {argument} in the document:
708
708
- Let {argumentName} be the Name of {argument}.
709
- - Let {argumentDefinition} be the argument definition provided by the parent
710
- field, fragment definition or directive definition named {argumentName}.
709
+ - If the parent is a field or directive:
710
+ - Let {argumentDefinition} be the argument or variable definition named {argumentName} provided by the parent
711
+ field definition, directive definition or fragment definition.
711
712
- {argumentDefinition} must exist.
712
713
713
714
** Explanatory Text**
714
715
715
- Every argument provided to a field or directive must be defined in the set of
716
- possible arguments of that field or directive .
716
+ Every argument provided to a field or directive or fragment spread must be defined in the set of
717
+ possible arguments of that field, directive or fragment .
717
718
718
719
For example the following are valid:
719
720
@@ -744,7 +745,7 @@ fragment invalidArgName on Dog {
744
745
}
745
746
```
746
747
747
- and this is also invalid as the argument ` dogCommand ` is not defined on fragment
748
+ and this is also invalid as the variable ` dogCommand ` is not defined on fragment
748
749
` withFragmentArg ` .
749
750
750
751
``` graphql counter-example
@@ -810,10 +811,9 @@ ambiguous and invalid.
810
811
#### Required Arguments
811
812
812
813
- For each Field, Fragment Spread or Directive in the document:
813
- - Let {arguments} be the arguments provided by the Field, Fragment Spread or
814
- Directive.
815
- - Let {argumentDefinitions} be the set of argument definitions of that Field,
816
- Fragment Spread or Directive.
814
+ - Let {arguments} be the arguments provided by the Field,
815
+ Directive or Fragment Spread.
816
+ - Let {argumentDefinitions} be the set of argument definitions of that Field or Directive, or the variable definitions of that Fragment.
817
817
- For each {argumentDefinition} in {argumentDefinitions}:
818
818
- Let {type} be the expected type of {argumentDefinition}.
819
819
- Let {defaultValue} be the default value of {argumentDefinition}.
@@ -1592,16 +1592,16 @@ query ($foo: Boolean = true, $bar: Boolean = false) {
1592
1592
1593
1593
** Formal Specification**
1594
1594
1595
- - For every {operation} in the document:
1596
- - For every {variable} defined on {operation}:
1595
+ - For every {operation} and {fragment} in the document:
1596
+ - For every {variable} defined on that {operation} or {fragment }:
1597
1597
- Let {variableName} be the name of {variable}.
1598
1598
- Let {variables} be the set of all variables named {variableName} on
1599
1599
{operation}.
1600
1600
- {variables} must be a set of one.
1601
1601
1602
1602
** Explanatory Text**
1603
1603
1604
- If any operation defines more than one variable with the same name, it is
1604
+ If any operation or fragment defines more than one variable with the same name, it is
1605
1605
ambiguous and invalid. It is invalid even if the type of the duplicate variable
1606
1606
is the same.
1607
1607
@@ -1632,12 +1632,28 @@ fragment HouseTrainedFragment on Query {
1632
1632
}
1633
1633
```
1634
1634
1635
+ Likewise, it is valid for both an operation and a fragment to define a variable with the same name:
1636
+ ``` graphql example
1637
+ query C ($atOtherHomes : Boolean ) {
1638
+ ... HouseTrainedFragment
1639
+ aDog : dog {
1640
+ ... HouseTrainedDog
1641
+ }
1642
+ }
1643
+
1644
+ fragment HouseTrainedDog ($atOtherHomes : Boolean ) on Dog {
1645
+ isHouseTrained (atOtherHomes : $atOtherHomes )
1646
+ }
1647
+ ```
1648
+
1649
+ Fragment-defined variables are scoped locally to the fragment that defines them, and override any operation-defined variable values, so there is never ambiguity about which value to use. In this case, the value of the argument ` atOtherHomes ` within ` HouseTrainedFragment ` will be the operation-set value, and within ` HouseTrainedDog ` will resolve to ` null ` , as the argument is not set by the fragment spread in the query ` C ` .
1650
+
1635
1651
### Variables Are Input Types
1636
1652
1637
1653
** Formal Specification**
1638
1654
1639
- - For every {operation} in a {document}:
1640
- - For every {variable} on each {operation}:
1655
+ - For every {operation} and {fragment} in a {document}:
1656
+ - For every {variable} defined on each {operation} or {fragment }:
1641
1657
- Let {variableType} be the type of {variable}.
1642
1658
- {IsInputType(variableType)} must be {true}.
1643
1659
@@ -1704,14 +1720,14 @@ query takesCatOrDog($catOrDog: CatOrDog) {
1704
1720
- Let {fragments} be every fragment referenced by that {operation}
1705
1721
transitively.
1706
1722
- For each {fragment} in {fragments}:
1707
- - For each {variableUsage} in scope of {fragment}, variable must be in
1723
+ - For each {variableUsage} in scope of {fragment}, variable must be in {fragment}'s or
1708
1724
{operation}'s variable list.
1709
1725
1710
1726
** Explanatory Text**
1711
1727
1712
- Variables are scoped on a per-operation basis. That means that any variable used
1713
- within the context of an operation must be defined at the top level of that
1714
- operation
1728
+ Operation-defined Variables are scoped on a per-operation basis, while Fragment-defined Variables are scoped locally to the fragment . That means that any variable used
1729
+ within the context of an operation must either be defined at the top level of that
1730
+ operation or on the fragment that uses that variable.
1715
1731
1716
1732
For example:
1717
1733
@@ -1738,8 +1754,8 @@ query variableIsNotDefined {
1738
1754
${atOtherHomes} is not defined by the operation.
1739
1755
1740
1756
Fragments complicate this rule. Any fragment transitively included by an
1741
- operation has access to the variables defined by that operation. Fragments can
1742
- appear within multiple operations and therefore variable usages must correspond
1757
+ operation has access to the variables defined by that operation and defined on the fragment . Fragments can
1758
+ appear within multiple operations and therefore variable usages not defined on the fragment must correspond
1743
1759
to variable definitions in all of those operations.
1744
1760
1745
1761
For example the following is valid:
@@ -1837,7 +1853,7 @@ This is because {houseTrainedQueryTwoNotDefined} does not define a variable
1837
1853
${atOtherHomes} but that variable is used by {isHouseTrainedFragment} which is
1838
1854
included in that operation.
1839
1855
1840
- ### All Variables Used
1856
+ ### All Operation Variables Used
1841
1857
1842
1858
** Formal Specification**
1843
1859
@@ -1945,20 +1961,20 @@ fragment isHouseTrainedFragment on Dog {
1945
1961
This document is not valid because {queryWithExtraVar} defines an extraneous
1946
1962
variable.
1947
1963
1948
- ### All Fragment Arguments Used
1964
+ ### All Fragment Variables Used
1949
1965
1950
1966
** Formal Specification**
1951
1967
1952
1968
- For every {fragment} in the document:
1953
- - Let {arguments } be the arguments defined by that {fragment}.
1954
- - Each {argument } in {arguments } must be used at least once in the fragment's
1969
+ - Let {variables } be the variables defined by that {fragment}.
1970
+ - Each {variable } in {variables } must be used at least once in the fragment's
1955
1971
scope.
1956
1972
1957
1973
** Explanatory Text**
1958
1974
1959
- All arguments defined by a fragment must be used in that same fragment. Because
1960
- fragment arguments are scoped to the fragment they are defined on, if the
1961
- fragment does not use the argument , then the argument is superfluous.
1975
+ All variables defined by a fragment must be used in that same fragment. Because
1976
+ fragment-defined variables are scoped to the fragment they are defined on, if the
1977
+ fragment does not use the variable , then the variable definition is superfluous.
1962
1978
1963
1979
For example, the following is invalid:
1964
1980
@@ -1974,8 +1990,8 @@ fragment fragmentArgUnused($atOtherHomes: Boolean) on Dog {
1974
1990
}
1975
1991
```
1976
1992
1977
- This document is invalid because even though ` fragmentArgUnused ` is spread with
1978
- the argument ` atOtherHomes ` , and even though ` $atOtherHomes ` is defined as an
1993
+ This document is invalid: even though ` fragmentArgUnused ` is spread with
1994
+ the argument ` atOtherHomes ` and ` $atOtherHomes ` is defined as an
1979
1995
operation variable, there is never a variable ` $atOtherHomes ` used within the
1980
1996
scope of ` fragmentArgUnused ` .
1981
1997
@@ -1987,9 +2003,9 @@ scope of `fragmentArgUnused`.
1987
2003
- Let {variableUsages} be all usages transitively included in the {operation}.
1988
2004
- For each {variableUsage} in {variableUsages}:
1989
2005
- Let {variableName} be the name of {variableUsage}.
1990
- - If the usage is within a {fragment} that defines an argument of
2006
+ - If the usage is within a {fragment} that defines a {variableDefinition} for
1991
2007
{variableName}:
1992
- - Let {variableDefinition} be the {ArgumentDefinition } named
2008
+ - Let {variableDefinition} be the {VariableDefinition } named
1993
2009
{variableName} defined within {fragment}.
1994
2010
- Otherwise, let {variableDefinition} be the {VariableDefinition} named
1995
2011
{variableName} defined within {operation}.
0 commit comments