Skip to content

Commit 2ac0f76

Browse files
committed
Clarify union-typed field selection validation. Fix: #84
1 parent 7fe69f9 commit 2ac0f76

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

spec/Section 5 -- Validation.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,31 @@ fragment definedOnImplementorsButNotInterface on Pet {
201201
}
202202
```
203203

204-
Because fields are not declared on unions, direct field selection on
205-
union-typed selection set. This is true even if concrete
206-
implementors of the union define the fieldName.
204+
Because unions do not define fields, fields may not be directly selected from a
205+
union-typed selection set, with the exception of the meta-field {__typename}.
206+
Fields from a union-typed selection set must only be queried indirectly via
207+
a fragment.
207208

208-
For example the following is invalid
209+
For example the following is valid:
209210

210-
```!graphql
211-
fragment directFieldSelectionOnUnion on CatOrDog {
212-
directField
211+
```graphql
212+
fragment inDirectFieldSelectionOnUnion on CatOrDog {
213+
__typename
214+
... on Pet {
215+
name
216+
}
217+
... on Dog {
218+
barkVolume
219+
}
213220
}
221+
```
222+
223+
But the following is invalid:
214224

215-
fragment definedOnImplementorsQueriedOnUnion on CatOrDog {
225+
```!graphql
226+
fragment directFieldSelectionOnUnion on CatOrDog {
216227
name
228+
barkVolume
217229
}
218230
```
219231

0 commit comments

Comments
 (0)