Skip to content

Commit 2a4d3ed

Browse files
committed
add rule requiring explicit listing of member types of child unions
1 parent 18e70e5 commit 2a4d3ed

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

spec/Section 3 -- Type System.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,12 +1372,13 @@ union SearchResult =
13721372

13731373
**Unions of Interfaces and Unions**
13741374

1375-
A Union may declare interfaces or other unions as member types. The parent
1376-
Union's possible types transitively include all the possible types of any
1377-
abstract member types. For example, the following types are valid:
1375+
A Union may declare interfaces or other unions as member types. Transitively
1376+
included object types (object types included within a union included by a union)
1377+
must also be included within the parent union. For example, the following types
1378+
are valid:
13781379

13791380
```graphql example
1380-
union SearchResult = Photo | Named
1381+
union SearchResult = Item | Photo | Video | Named
13811382

13821383
interface Named {
13831384
name: String
@@ -1425,6 +1426,13 @@ And, given the above, the following operation is valid:
14251426
}
14261427
```
14271428

1429+
While the following union is invalid, because the member types of `Item` are not
1430+
explicitly included within `SearchResult`:
1431+
1432+
```graphql counter-example
1433+
union SearchResult = Item | Named
1434+
```
1435+
14281436
**Result Coercion**
14291437

14301438
The union type should have some way of determining which object a given result
@@ -1443,6 +1451,12 @@ Union types have the potential to be invalid if incorrectly defined.
14431451
2. The member types of a Union type must all be Object, Interface or Union
14441452
types; Scalar and Enum types must not be member types of a Union. Similarly,
14451453
wrapping types must not be member types of a Union.
1454+
3. A parent Union must explicitly include as member types of all child Union
1455+
members.
1456+
1. Let this union type be {unionType}.
1457+
2. For each {memberType} declared as a member of {unionType}, if {memberType}
1458+
is a Union type, all of the members of {memberType} must also be members
1459+
of {unionType}.
14461460

14471461
### Union Extensions
14481462

@@ -1469,6 +1483,12 @@ Union type extensions have the potential to be invalid if incorrectly defined.
14691483
the original Union type.
14701484
5. Any non-repeatable directives provided must not already apply to the original
14711485
Union type.
1486+
6. A parent Union must explicitly include as member types of all child Union
1487+
members.
1488+
1. Let this union type be {unionType}.
1489+
2. For each {memberType} declared as a member of {unionType}, if {memberType}
1490+
is a Union type, all of the members of {memberType} must also be members
1491+
of {unionType}.
14721492

14731493
## Enums
14741494

0 commit comments

Comments
 (0)