Skip to content

Commit

Permalink
unions implementing interfaces have fields
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed May 23, 2022
1 parent 2b42f6b commit a9d5bc9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
29 changes: 22 additions & 7 deletions spec/Section 3 -- Type System.md
Original file line number Diff line number Diff line change
Expand Up @@ -1305,16 +1305,15 @@ UnionMemberTypes :
- = `|`? NamedType

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

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

For example, we might define the following types:

Expand Down Expand Up @@ -1399,6 +1398,22 @@ type Photo implements Resource {
}
```

The following query would then be valid:

```graphql example
{
firstSearchResult {
url
... on Article {
title
}
... on Photo {
height
}
}
}
```

Transitively implemented interfaces (interfaces implemented by the interface
that is being implemented) must also be defined on the implementing union. For
example, `SearchResult` cannot implement `Resource` without also implementing
Expand Down
3 changes: 3 additions & 0 deletions spec/Section 4 -- Introspection.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ Fields\:
- `kind` must return `__TypeKind.UNION`.
- `name` must return a String.
- `description` may return a String or {null}.
- `fields` must return the set of fields that can be selected for this type.
- Accepts the argument `includeDeprecated` which defaults to {false}. If
{true}, deprecated fields are also returned.
- `possibleTypes` returns the list of types that can be represented within this
union. They must be object types.
- All other fields must return {null}.
Expand Down

0 comments on commit a9d5bc9

Please sign in to comment.