Skip to content

Commit b025653

Browse files
committed
{operation,fragment}-defined variable -> {operation,fragment} variable
1 parent 4805a96 commit b025653

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

spec/Section 2 -- Language.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,20 +1283,28 @@ size `60`:
12831283

12841284
**Variable Use Within Fragments**
12851285

1286-
Variables can be used within fragments. Operation-defined variables have global
1287-
scope within a given operation. Fragment-defined variables have local scope
1288-
within the fragment definition in which they are defined. A variable used within
1289-
a fragment must either be declared in each top-level operation that transitively
1290-
consumes that fragment, or by that same fragment as a fragment variable
1291-
definition. If a variable referenced in a fragment is included by an operation
1292-
where neither the fragment nor the operation defines that variable, that
1293-
operation is invalid (see
1294-
[All Variable Uses Defined](#sec-All-Variable-Uses-Defined)).
1286+
Variables can be used within fragments.
1287+
1288+
:: An _operation variable_ is a variable defined on an operation. An operation
1289+
variable has global scope within that operation, including within any fragments
1290+
that operation transitively consumes.
1291+
1292+
:: A _fragment variable_ is a variable defined on a fragment. A fragment
1293+
variable is locally scoped, it may only be referenced within that fragment
1294+
(non-transitively).
1295+
1296+
A variable used within a fragment must either be defined by that fragment, or
1297+
must be declared in each top-level operation that transitively consumes that
1298+
fragment. If a variable referenced in a fragment is defined in both the fragment
1299+
and the operation, the fragment definition will be used. If a variable is
1300+
referenced in a fragment and is not defined by that fragment, then any operation
1301+
that transitively references the fragment and does not define that variable is
1302+
invalid (see [All Variable Uses Defined](#sec-All-Variable-Uses-Defined)).
12951303

12961304
## Fragment Variable Definitions
12971305

1298-
Fragments may define locally scoped variables. This allows fragments to be
1299-
reused while enabling the caller to specify the fragment's behavior.
1306+
Fragments may define locally scoped variables. This allows the caller to specify
1307+
the fragment's behavior.
13001308

13011309
For example, the profile picture may need to be a different size depending on
13021310
the parent context:
@@ -1321,8 +1329,8 @@ fragment dynamicProfilePic($size: Int! = 50) on User {
13211329
In this case the `user` will have a larger `profilePic` than those found in the
13221330
list of `friends`.
13231331

1324-
A fragment-defined variable is scoped to the fragment that defines it.
1325-
Fragment-defined variables are allowed to shadow operation-defined variables.
1332+
A _fragment variable_ is scoped to the fragment that defines it. A fragment
1333+
variable may shadow an _operation variable_.
13261334

13271335
```graphql example
13281336
query withShadowedVariables($size: Int!) {
@@ -1345,9 +1353,9 @@ fragment dynamicProfilePic($size: Int!) on User {
13451353

13461354
The profilePic for `user` will be determined by the variables set by the
13471355
operation, while `secondUser` will always have a `profilePic` of size `10`. In
1348-
this case, the fragment `variableProfilePic` uses the operation-defined
1349-
variable, while `dynamicProfilePic` uses the value passed in via the fragment
1350-
spread's `size` argument.
1356+
this case, the fragment `variableProfilePic` uses the _operation variable_,
1357+
while `dynamicProfilePic` uses the value passed in via the fragment spread's
1358+
`size` argument.
13511359

13521360
## Type References
13531361

spec/Section 5 -- Validation.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,12 +1853,12 @@ fragment HouseTrainedDog($atOtherHomes: Boolean) on Dog {
18531853
}
18541854
```
18551855

1856-
Fragment-defined variables are scoped locally to the fragment that defines them,
1857-
and override any operation-defined variable values, so there is never ambiguity
1858-
about which value to use. In this case, the value of the argument `atOtherHomes`
1859-
within `HouseTrainedFragment` will be the operation-set value, and within
1860-
`HouseTrainedDog` will default to being unset (unless a default-value applies),
1861-
as the argument is not set by the fragment spread in the query `C`.
1856+
A _fragment variable_ is scoped locally to the fragment that defines it, and
1857+
overrides the _operation variable_ of the same name, if any, so there is never
1858+
ambiguity about which value to use. In this case, the value of the argument
1859+
`atOtherHomes` within `HouseTrainedFragment` will be the operation-set value,
1860+
and within `HouseTrainedDog` will default to being unset (unless a default-value
1861+
applies), as the argument is not set by the fragment spread in the query `C`.
18621862

18631863
### Variables Are Input Types
18641864

@@ -1938,10 +1938,10 @@ query takesCatOrDog($catOrDog: CatOrDog) {
19381938

19391939
**Explanatory Text**
19401940

1941-
Operation-defined Variables are scoped on a per-operation basis, while
1942-
Fragment-defined Variables are scoped locally to the fragment. That means that
1943-
any variable used within the context of an operation must either be defined at
1944-
the top level of that operation or on the fragment that uses that variable.
1941+
An _operation variable_ is scoped on a per-operation basis, while a _fragment
1942+
variable_ is scoped locally to the fragment. That means that any variable used
1943+
within the context of an operation must either be defined at the top level of
1944+
that operation or on the fragment that uses that variable.
19451945

19461946
For example:
19471947

@@ -2134,7 +2134,7 @@ fragment isHouseTrainedWithoutVariableFragment on Dog {
21342134
```
21352135

21362136
Fragment arguments can shadow operation variables: fragments that use an
2137-
argument are not using the operation-defined variable of the same name.
2137+
argument are not using the _operation variable_ of the same name.
21382138

21392139
As such, it would be invalid if the operation defined a variable and variables
21402140
of that name were used exclusively inside fragments that define a variable with
@@ -2154,8 +2154,8 @@ fragment shadowedVariableFragment($atOtherHomes: Boolean) on Dog {
21542154

21552155
because
21562156
{$atOtherHomes} is only referenced in a fragment that defines it as a
2157-
locally scoped argument, the operation-defined {$atOtherHomes}
2158-
variable is never used.
2157+
locally scoped argument, the _operation variable_ {$atOtherHomes}
2158+
is never used.
21592159

21602160
All operations in a document must use all of their variables.
21612161

0 commit comments

Comments
 (0)