Skip to content

Commit a9d5bc9

Browse files
committed
unions implementing interfaces have fields
1 parent 2b42f6b commit a9d5bc9

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

spec/Section 3 -- Type System.md

+22-7
Original file line numberDiff line numberDiff line change
@@ -1305,16 +1305,15 @@ UnionMemberTypes :
13051305
- = `|`? NamedType
13061306

13071307
GraphQL Unions represent an object that could be one of a list of GraphQL Object
1308-
types, but provides for no guaranteed fields between those types. They also
1309-
differ from interfaces in that Object types declare what interfaces they
1310-
implement, but are not aware of what unions contain them.
1308+
types. They differ from interfaces in that Object types declare what interfaces
1309+
they implement, but are not aware of what unions contain them.
13111310

13121311
With interfaces and objects, only those fields defined on the type can be
13131312
queried directly; to query other fields on an interface, typed fragments must be
1314-
used. This is the same as for unions, but unions do not define any fields, so
1315-
**no** fields may be queried on this type without the use of type refining
1316-
fragments or inline fragments (with the exception of the meta-field
1317-
{\_\_typename}).
1313+
used. This is the same as for unions, but unions do not directly define any
1314+
fields, so the only fields that may be queried on a Union are the meta-field
1315+
{\_\_typename} and the fields of the interfaces that the Union declares it
1316+
implements (see [Unions Implementing Interfaces](#sec-Unions.Unions-Implementing-Interfaces)). Otherwise, type refining fragments or inline fragments must be used.
13181317

13191318
For example, we might define the following types:
13201319

@@ -1399,6 +1398,22 @@ type Photo implements Resource {
13991398
}
14001399
```
14011400

1401+
The following query would then be valid:
1402+
1403+
```graphql example
1404+
{
1405+
firstSearchResult {
1406+
url
1407+
... on Article {
1408+
title
1409+
}
1410+
... on Photo {
1411+
height
1412+
}
1413+
}
1414+
}
1415+
```
1416+
14021417
Transitively implemented interfaces (interfaces implemented by the interface
14031418
that is being implemented) must also be defined on the implementing union. For
14041419
example, `SearchResult` cannot implement `Resource` without also implementing

spec/Section 4 -- Introspection.md

+3
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ Fields\:
306306
- `kind` must return `__TypeKind.UNION`.
307307
- `name` must return a String.
308308
- `description` may return a String or {null}.
309+
- `fields` must return the set of fields that can be selected for this type.
310+
- Accepts the argument `includeDeprecated` which defaults to {false}. If
311+
{true}, deprecated fields are also returned.
309312
- `possibleTypes` returns the list of types that can be represented within this
310313
union. They must be object types.
311314
- All other fields must return {null}.

0 commit comments

Comments
 (0)