@@ -923,8 +923,8 @@ IsValidImplementationFieldType(fieldType, implementedFieldType):
923
923
3. Return {IsValidImplementationFieldType (itemType, implementedItemType)}.
924
924
3. If {fieldType } is the same type as {implementedFieldType } then return {true }.
925
925
4. If {fieldType } is an Object type and {implementedFieldType } is a Union type
926
- and {fieldType } is a possible type of {implementedFieldType } then return
927
- {true }.
926
+ and {fieldType } is a possible type or member type of {implementedFieldType }
927
+ then return {true }.
928
928
5. If {fieldType } is an Object or Interface type and {implementedFieldType } is
929
929
an Interface type and {fieldType } declares it implements
930
930
{implementedFieldType } then return {true }.
@@ -1302,8 +1302,8 @@ UnionMemberTypes :
1302
1302
- = `|`? NamedType
1303
1303
1304
1304
GraphQL Unions represent an object that could be one of a list of GraphQL Object
1305
- types , but provides for no guaranteed fields between those types . They also
1306
- differ from interfaces in that Object types declare what interfaces they
1305
+ types , providing for no guaranteed fields between those types . They differ from
1306
+ interfaces in that Object and Interface types declare what interfaces they
1307
1307
implement , but are not aware of what unions contain them .
1308
1308
1309
1309
With interfaces and objects , only those fields defined on the type can be
@@ -1370,6 +1370,61 @@ union SearchResult =
1370
1370
| Person
1371
1371
```
1372
1372
1373
+ **Unions of Interfaces and Unions **
1374
+
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 :
1378
+
1379
+ ```graphql example
1380
+ union SearchResult = Photo | Named
1381
+
1382
+ interface Named {
1383
+ name : String
1384
+ }
1385
+
1386
+ type Person {
1387
+ name : String
1388
+ age : Int
1389
+ }
1390
+
1391
+ union Item = Photo | Video
1392
+
1393
+ type Photo {
1394
+ height : Int
1395
+ width : Int
1396
+ }
1397
+
1398
+ type Video {
1399
+ codec : String
1400
+ }
1401
+
1402
+ type SearchQuery {
1403
+ firstSearchResult : SearchResult
1404
+ }
1405
+ ```
1406
+
1407
+ And , given the above , the following operation is valid :
1408
+
1409
+ ```graphql example
1410
+ {
1411
+ firstSearchResult {
1412
+ ... on Named {
1413
+ name
1414
+ }
1415
+ ... on Person {
1416
+ age
1417
+ }
1418
+ ... on Photo {
1419
+ height
1420
+ }
1421
+ ... on Video {
1422
+ codec
1423
+ }
1424
+ }
1425
+ }
1426
+ ```
1427
+
1373
1428
**Result Coercion **
1374
1429
1375
1430
The union type should have some way of determining which object a given result
@@ -1385,8 +1440,8 @@ Unions are never valid inputs.
1385
1440
Union types have the potential to be invalid if incorrectly defined .
1386
1441
1387
1442
1. A Union type must include one or more unique member types .
1388
- 2. The member types of a Union type must all be Object base types ; Scalar ,
1389
- Interface and Union types must not be member types of a Union . Similarly ,
1443
+ 2. The member types of a Union type must all be Object , Interface or Union
1444
+ types ; Scalar and Enum types must not be member types of a Union . Similarly ,
1390
1445
wrapping types must not be member types of a Union .
1391
1446
1392
1447
### Union Extensions
@@ -1406,9 +1461,9 @@ another GraphQL service.
1406
1461
Union type extensions have the potential to be invalid if incorrectly defined .
1407
1462
1408
1463
1. The named type must already be defined and must be a Union type .
1409
- 2. The member types of a Union type extension must all be Object base types ;
1410
- Scalar , Interface and Union types must not be member types of a Union .
1411
- Similarly , wrapping types must not be member types of a Union .
1464
+ 2. The member types of a Union type must all be Object , Interface or Union
1465
+ types ; Scalar and Enum types must not be member types of a Union . Similarly ,
1466
+ wrapping types must not be member types of a Union .
1412
1467
3. All member types of a Union type extension must be unique .
1413
1468
4. All member types of a Union type extension must not already be a member of
1414
1469
the original Union type .
0 commit comments