Skip to content

Commit 641e3d9

Browse files
committed
update validation
1 parent b07931f commit 641e3d9

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

spec/Section 5 -- Validation.md

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,29 @@ validation fails because the fragment spread `...commandFragment(command: SIT)`
609609
and `...commandFragment(command: DOWN)` are part of the visited selections that
610610
will be merged.
611611

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+
```
614635

615636
### Leaf Field Selections
616637

@@ -1873,7 +1894,7 @@ This is because {houseTrainedQueryTwoNotDefined} does not define a variable
18731894
${atOtherHomes} but that variable is used by {isHouseTrainedFragment} which is
18741895
included in that operation.
18751896

1876-
### All Operation Variables Used
1897+
### All Variables Used
18771898

18781899
**Formal Specification**
18791900

@@ -1882,6 +1903,11 @@ included in that operation.
18821903
- Each {variable} in {variables} must be used at least once in either the
18831904
operation scope itself or any fragment transitively referenced by that
18841905
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.
18851911

18861912
**Explanatory Text**
18871913

@@ -1982,24 +2008,8 @@ fragment isHouseTrainedFragment on Dog {
19822008
This document is not valid because {queryWithExtraVar} defines an extraneous
19832009
variable.
19842010

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:
20032013

20042014
```graphql counter-example
20052015
query queryWithFragmentArgUnused($atOtherHomes: Boolean) {

0 commit comments

Comments
 (0)