Skip to content

Commit 89475ac

Browse files
committed
Validation/Variables/Variable Uniqueness
1 parent 48243bf commit 89475ac

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

spec/Section 5 -- Validation.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,52 @@ usage of a directive, the directive must be available on that server.
11021102

11031103
## Variables
11041104

1105+
### Variable Uniqueness
1106+
1107+
** Formal Specification **
1108+
1109+
* For every {operation} in the document
1110+
* For every {variable} defined on {operation}
1111+
* Let {variableName} be the name of {variable}
1112+
* Let {variables} be the set of all variables named {variableName} on
1113+
{operation}
1114+
* {variables} must be a set of one
1115+
1116+
** Explanatory Text **
1117+
1118+
If any operation defines more than one variable with the same name, it is
1119+
ambiguous and invalid. It is invalid even if the type of the duplicate variable
1120+
is the same.
1121+
1122+
```!graphql
1123+
query houseTrainedQuery($atOtherHomes: Boolean, $atOtherHomes: Boolean) {
1124+
dog {
1125+
isHousetrained(atOtherHomes: $atOtherHomes)
1126+
}
1127+
}
1128+
```
1129+
1130+
1131+
It is valid for multiple operations to define a variable with the same name. If
1132+
two operations reference the same fragment, it might actually be necessary:
1133+
1134+
```graphql
1135+
query A($atOtherHomes: Boolean) {
1136+
...HouseTrainedFragment
1137+
}
1138+
1139+
query B($atOtherHomes: Boolean) {
1140+
...HouseTrainedFragment
1141+
}
1142+
1143+
fragment HouseTrainedFragment {
1144+
dog {
1145+
isHousetrained(atOtherHomes: $atOtherHomes)
1146+
}
1147+
}
1148+
```
1149+
1150+
11051151
### Variable Default Values Are Correctly Typed
11061152

11071153
** Formal Specification **

0 commit comments

Comments
 (0)