@@ -261,6 +261,7 @@ TypeDefinition :
261
261
- ObjectTypeDefinition
262
262
- InterfaceTypeDefinition
263
263
- UnionTypeDefinition
264
+ - IntersectionTypeDefinition
264
265
- EnumTypeDefinition
265
266
- InputObjectTypeDefinition
266
267
@@ -276,7 +277,7 @@ Scalars and Enums form the leaves in response trees; the intermediate levels are
276
277
` Object ` types, which define a set of fields, where each field is another type
277
278
in the system, allowing the definition of arbitrary type hierarchies.
278
279
279
- GraphQL supports two abstract types: interfaces and unions .
280
+ GraphQL supports three abstract types: interfaces, unions and intersections .
280
281
281
282
An ` Interface ` defines a list of fields; ` Object ` types and other Interface
282
283
types which implement this Interface are guaranteed to implement those fields.
@@ -287,6 +288,11 @@ A `Union` defines a list of possible types; similar to interfaces, whenever the
287
288
type system claims a union will be returned, one of the possible types will be
288
289
returned.
289
290
291
+ An ` Intersection ` defines a list of constraining abstract types. If a field
292
+ claims it returns an Intersection type, it will return only types that are
293
+ contained within all of the Intersections's Unions and types that implement all
294
+ of the Intersection's Interfaces.
295
+
290
296
Finally, oftentimes it is useful to provide complex structs as inputs to GraphQL
291
297
field arguments or variables; the ` Input Object ` type allows the schema to
292
298
define exactly what data is expected.
@@ -314,9 +320,9 @@ to arguments and variables as well as the values output by fields. These two
314
320
uses categorize types as _ input types_ and _ output types_ . Some kinds of types,
315
321
like Scalar and Enum types, can be used as both input types and output types;
316
322
other kinds of types can only be used in one or the other. Input Object types
317
- can only be used as input types. Object, Interface, and Union types can only be
318
- used as output types. Lists and Non-Null types may be used as input types or
319
- output types depending on how the wrapped type may be used.
323
+ can only be used as input types. Object, Interface, Union, and Intersection
324
+ types can only be used as output types. Lists and Non-Null types may be used as
325
+ input types or output types depending on how the wrapped type may be used.
320
326
321
327
IsInputType(type) :
322
328
@@ -332,7 +338,7 @@ IsOutputType(type) :
332
338
- If {type} is a List type or Non-Null type:
333
339
- Let {unwrappedType} be the unwrapped type of {type}.
334
340
- Return IsOutputType({unwrappedType})
335
- - If {type} is a Scalar, Object, Interface, Union, or Enum type:
341
+ - If {type} is a Scalar, Object, Interface, Union, Intersection, or Enum type:
336
342
- Return {true}
337
343
- Return {false}
338
344
@@ -706,8 +712,8 @@ Must only yield exactly that subset:
706
712
```
707
713
708
714
A field of an Object type may be a Scalar , Enum , another Object type , an
709
- Interface , or a Union . Additionally , it may be any wrapping type whose
710
- underlying base type is one of those five .
715
+ Interface , a Union , or an Intersection . Additionally , it may be any wrapping
716
+ type whose underlying base type is one of those five .
711
717
712
718
For example , the `Person ` type might include a `relationship `:
713
719
@@ -928,7 +934,13 @@ IsValidImplementationFieldType(fieldType, implementedFieldType):
928
934
5. If {fieldType } is an Object or Interface type and {implementedFieldType } is
929
935
an Interface type and {fieldType } declares it implements
930
936
{implementedFieldType } then return {true }.
931
- 6. Otherwise return {false }.
937
+ 6. If {fieldType } is an IntersectionType and {implementedFieldType } is an Union
938
+ type and {fieldType } is a member type of {implementedFieldType } then return
939
+ {true }.
940
+ 7. If {fieldType } is an IntersectionType and {implementedFieldType } is an
941
+ Interface type and at least one of the members of {fieldType } declares it
942
+ implements {implementedFieldType } then return {true }.
943
+ 8. Otherwise return {false }.
932
944
933
945
### Field Arguments
934
946
@@ -977,7 +989,7 @@ May return the result:
977
989
```
978
990
979
991
The type of an object field argument must be an input type (any type except an
980
- Object, Interface, or Union type).
992
+ Object, Interface, Union, or Intersection type).
981
993
982
994
### Field Deprecation
983
995
@@ -1054,8 +1066,8 @@ objects and interfaces can then implement these interfaces which requires that
1054
1066
the implementing type will define all fields defined by those interfaces .
1055
1067
1056
1068
Fields on a GraphQL interface have the same rules as fields on a GraphQL object ;
1057
- their type can be Scalar , Object , Enum , Interface , or Union , or any wrapping
1058
- type whose base type is one of those five .
1069
+ their type can be Scalar , Object , Enum , Interface , Union , or Intersection , or
1070
+ any wrapping type whose base type is one of those five .
1059
1071
1060
1072
For example , an interface `NamedEntity ` may describe a required field and types
1061
1073
such as `Person ` or `Business ` may then implement this interface to guarantee
@@ -1415,6 +1427,154 @@ Union type extensions have the potential to be invalid if incorrectly defined.
1415
1427
5. Any non -repeatable directives provided must not already apply to the original
1416
1428
Union type .
1417
1429
1430
+ ## Intersections
1431
+
1432
+ IntersectionTypeDefinition : Description ? intersection Name Directives [Const ]?
1433
+ IntersectionMemberTypes ?
1434
+
1435
+ IntersectionMemberTypes :
1436
+
1437
+ - IntersectionMemberTypes | NamedType
1438
+ - = `|`? NamedType
1439
+
1440
+ GraphQL Intersections are higher order abstract types that represent objects
1441
+ satisfying the requirements of all of the Intersection 's abstract member types .
1442
+ Intersections combine the features of interfaces and unions ; the objects
1443
+ represented by an Intersection must implement all of the Intersection 's
1444
+ interfaces and must also be included within all of its unions .
1445
+
1446
+ Just as with unions , intersections do not directly define any fields , so **no **
1447
+ fields may be queried on this type without the use of type refining fragments or
1448
+ inline fragments (with the exception of the meta-field {\_\_typename}).
1449
+
1450
+ For example , we might define the following types :
1451
+
1452
+ ```graphql example
1453
+ interface Link {
1454
+ link : Downloadable
1455
+ }
1456
+
1457
+ type SearchResultLink implements Link {
1458
+ link : DownloadableSearchResult
1459
+ }
1460
+
1461
+ interface Downloadable {
1462
+ url : string
1463
+ }
1464
+
1465
+ union SearchResult = Photo | Person
1466
+
1467
+ intersection DownloadableSearchResult = SearchResult & Downloadable
1468
+
1469
+ type Person implements Downloadable {
1470
+ url : String
1471
+ name : String
1472
+ age : Int
1473
+ }
1474
+
1475
+ type Photo implements Downloadable {
1476
+ url : String
1477
+ height : Int
1478
+ width : Int
1479
+ }
1480
+
1481
+ type SearchQuery {
1482
+ firstDownloadableSearchResult : DownloadableSearchResult
1483
+ }
1484
+ ```
1485
+
1486
+ Because intersection `DownloadableSearchResult ` includes interface
1487
+ `Downloadable ` as a constraining member type , the possible types of the
1488
+ intersection implement the `Downloadable ` interface . The `link ` field within
1489
+ `SearchResultLink ` therefore implements the `link ` field of interface `Link `.
1490
+
1491
+ Just as with unions , the below could be ambiguous and is invalid .
1492
+
1493
+ ```graphql counter -example
1494
+ {
1495
+ firstDownloadableSearchResult {
1496
+ url
1497
+ name
1498
+ height
1499
+ }
1500
+ }
1501
+ ```
1502
+
1503
+ A valid operation includes typed fragments (in this example, inline fragments):
1504
+
1505
+ ```graphql example
1506
+ {
1507
+ firstDownloadableSearchResult {
1508
+ ... on Downloadable {
1509
+ url
1510
+ }
1511
+ ... on Person {
1512
+ name
1513
+ }
1514
+ ... on Photo {
1515
+ height
1516
+ }
1517
+ }
1518
+ }
1519
+ ```
1520
+
1521
+ Intersection members may be defined with an optional leading `&` character to
1522
+ aid formatting when representing a longer list of constraining types :
1523
+
1524
+ ```raw graphql example
1525
+ intersection DownloadableSearchResult =
1526
+ & Downloadable
1527
+ & SearchResult
1528
+ ```
1529
+
1530
+ **Result Coercion **
1531
+
1532
+ The intersection type should have some way of determining which object a given
1533
+ result corresponds to . Once it has done so , the result coercion of the
1534
+ intersection is the same as the result coercion of the object .
1535
+
1536
+ **Input Coercion **
1537
+
1538
+ Intersections are never valid inputs .
1539
+
1540
+ **Type Validation **
1541
+
1542
+ Intersection types have the potential to be invalid if incorrectly defined .
1543
+
1544
+ 1. An Intersection type must include one or more unique member types .
1545
+ 2. The member types of a Intersection type must all be Interface or Union base
1546
+ types ; Scalar , Enum , Object and other Intersection types must not be member
1547
+ types of an Intersection . Similarly , wrapping types must not be member types
1548
+ of an Intersection .
1549
+
1550
+ ### Intersection Extensions
1551
+
1552
+ IntersectionTypeExtension :
1553
+
1554
+ - extend intersection Name Directives [Const ]? IntersectionMemberTypes
1555
+ - extend intersection Name Directives [Const ]
1556
+
1557
+ Intersection type extensions are used to represent an intersection type which
1558
+ has been extended from some original intersection type . Similar to unions , this
1559
+ might by utilized by a GraphQL service which is itself an extension of another
1560
+ GraphQL service .
1561
+
1562
+ **Type Validation **
1563
+
1564
+ Intersection type extensions have the potential to be invalid if incorrectly
1565
+ defined .
1566
+
1567
+ 1. The named type must already be defined and must be a Intersection type .
1568
+ 2. The member types of a Intersection type must all be Interface or Union base
1569
+ types ; Scalar , Enum , Object and other Intersection types must not be member
1570
+ types of an Intersection . Similarly , wrapping types must not be member types
1571
+ of an Intersection .
1572
+ 3. All member types of an Intersection type extension must be unique .
1573
+ 4. All member types of an Intersection type extension must not already be a
1574
+ member of the original Intersection type .
1575
+ 5. Any non -repeatable directives provided must not already apply to the original
1576
+ Intersection type .
1577
+
1418
1578
## Enums
1419
1579
1420
1580
EnumTypeDefinition :
@@ -1876,6 +2036,7 @@ TypeSystemDirectiveLocation : one of
1876
2036
- `ARGUMENT_DEFINITION `
1877
2037
- `INTERFACE `
1878
2038
- `UNION `
2039
+ - `INTERSECTION `
1879
2040
- `ENUM `
1880
2041
- `ENUM_VALUE `
1881
2042
- `INPUT_OBJECT `
0 commit comments