@@ -609,8 +609,29 @@ validation fails because the fragment spread `...commandFragment(command: SIT)`
609
609
and ` ...commandFragment(command: DOWN) ` are part of the visited selections that
610
610
will be merged.
611
611
612
- If both of these spreads had used the same variable for the argument value, it
613
- would be allowed as we can be sure that we'd resolve identical fields.
612
+ If both of these spreads had used the same value for the argument value, it
613
+ would be allowed as we can be sure that we would resolve identical fields.
614
+ Spreads that use different variables that would always resolve to the same value
615
+ are also valid. For example, the following is valid:
616
+
617
+ ``` graphql example
618
+ fragment commandFragment ($command : DogCommand ! ) on Dog {
619
+ doesKnowCommand (dogCommand : $command )
620
+ }
621
+
622
+ fragment noConflictWhenPassedOperationCommand (
623
+ $fragmentCommand : DogCommand !
624
+ ) on Dog {
625
+ ... commandFragment (command : $operationCommand )
626
+ ... commandFragment (command : $fragmentCommand )
627
+ }
628
+
629
+ query ($operationCommand : DogCommand ! ) {
630
+ pet {
631
+ ... noConflictWhenPassedOperationCommand (fragmentCommand : $operationCommand )
632
+ }
633
+ }
634
+ ```
614
635
615
636
### Leaf Field Selections
616
637
@@ -1873,7 +1894,7 @@ This is because {houseTrainedQueryTwoNotDefined} does not define a variable
1873
1894
${atOtherHomes} but that variable is used by {isHouseTrainedFragment} which is
1874
1895
included in that operation.
1875
1896
1876
- ### All Operation Variables Used
1897
+ ### All Variables Used
1877
1898
1878
1899
** Formal Specification**
1879
1900
@@ -1882,6 +1903,11 @@ included in that operation.
1882
1903
- Each {variable} in {variables} must be used at least once in either the
1883
1904
operation scope itself or any fragment transitively referenced by that
1884
1905
operation, excluding fragments that define the same name as an argument.
1906
+ - For every {fragment} in the document:
1907
+ - Let {variables} be the variables defined by that {fragment}.
1908
+ - Each {variable} in {variables} must be used at least once transitively
1909
+ within the fragment's selection set excluding traversal of named fragment
1910
+ spreads.
1885
1911
1886
1912
** Explanatory Text**
1887
1913
@@ -1982,24 +2008,8 @@ fragment isHouseTrainedFragment on Dog {
1982
2008
This document is not valid because {queryWithExtraVar} defines an extraneous
1983
2009
variable.
1984
2010
1985
- ### All Fragment Variables Used
1986
-
1987
- ** Formal Specification**
1988
-
1989
- - For every {fragment} in the document:
1990
- - Let {variables} be the variables defined by that {fragment}.
1991
- - Each {variable} in {variables} must be used at least once transitively
1992
- within the fragment's selection set excluding traversal of named fragment
1993
- spreads.
1994
-
1995
- ** Explanatory Text**
1996
-
1997
- All variables defined by a fragment must be used in that same fragment. Because
1998
- fragment-defined variables are scoped to the fragment they are defined on, if
1999
- the fragment does not use the variable, then the variable definition is
2000
- superfluous.
2001
-
2002
- For example, the following is invalid:
2011
+ Fragment variables must also be used within their definitions. For example, the
2012
+ following is invalid:
2003
2013
2004
2014
``` graphql counter-example
2005
2015
query queryWithFragmentArgUnused ($atOtherHomes : Boolean ) {
0 commit comments