@@ -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,141 @@ 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
+ union SearchResult = Photo | Person
1454
+
1455
+ interface Downloadable = {
1456
+ url : String
1457
+ }
1458
+
1459
+ intersection DownloadableSearchResult = SearchResult & Downloadable
1460
+
1461
+ type Person implements Downloadable {
1462
+ url : String
1463
+ name : String
1464
+ age : Int
1465
+ }
1466
+
1467
+ type Photo implements Downloadable {
1468
+ url : String
1469
+ height : Int
1470
+ width : Int
1471
+ }
1472
+
1473
+ type SearchQuery {
1474
+ firstDownlodableSearchResult : DownloadableSearchResult
1475
+ }
1476
+ ```
1477
+
1478
+ Just as with unions , the below could be ambiguous and is invalid .
1479
+
1480
+ ```graphql counter -example
1481
+ {
1482
+ firstDownloadableSearchResult {
1483
+ url
1484
+ name
1485
+ height
1486
+ }
1487
+ }
1488
+ ```
1489
+
1490
+ A valid operation includes typed fragments (in this example, inline fragments):
1491
+
1492
+ ```graphql example
1493
+ {
1494
+ firstDownloadableSearchResult {
1495
+ ... on Downloadable {
1496
+ url
1497
+ }
1498
+ ... on Person {
1499
+ name
1500
+ }
1501
+ ... on Photo {
1502
+ height
1503
+ }
1504
+ }
1505
+ }
1506
+ ```
1507
+
1508
+ Intersection members may be defined with an optional leading `&` character to
1509
+ aid formatting when representing a longer list of constraining types :
1510
+
1511
+ ```raw graphql example
1512
+ intersection DownloadableSearchResult =
1513
+ & Downloadable
1514
+ & SearchResult
1515
+ ```
1516
+
1517
+ **Result Coercion **
1518
+
1519
+ The intersection type should have some way of determining which object a given
1520
+ result corresponds to . Once it has done so , the result coercion of the
1521
+ intersection is the same as the result coercion of the object .
1522
+
1523
+ **Input Coercion **
1524
+
1525
+ Intersections are never valid inputs .
1526
+
1527
+ **Type Validation **
1528
+
1529
+ Intersection types have the potential to be invalid if incorrectly defined .
1530
+
1531
+ 1. An Intersection type must include one or more unique member types .
1532
+ 2. The member types of a Intersection type must all be Interface , Union or
1533
+ Intersection base types ; Scalar , Enum and Object types must not be member
1534
+ types of an an Intersection . Similarly , wrapping types must not be member
1535
+ types of an Intersection .
1536
+
1537
+ ### Intersection Extensions
1538
+
1539
+ IntersectionTypeExtension :
1540
+
1541
+ - extend intersection Name Directives [Const ]? IntersectionMemberTypes
1542
+ - extend intersection Name Directives [Const ]
1543
+
1544
+ Intersection type extensions are used to represent an intersection type which
1545
+ has been extended from some original intersection type . Similar to unions , this
1546
+ might by utilized by a GraphQL service which is itself an extension of another
1547
+ GraphQL service .
1548
+
1549
+ **Type Validation **
1550
+
1551
+ Intersection type extensions have the potential to be invalid if incorrectly
1552
+ defined .
1553
+
1554
+ 1. The named type must already be defined and must be a Intersection type .
1555
+ 2. The member types of a Intersection type must all be Interface , Union or
1556
+ Intersection base types ; Scalar , Enum and Object types must not be member
1557
+ types of an an Intersection . Similarly , wrapping types must not be member
1558
+ types of an Intersection .
1559
+ 3. All member types of an Intersection type extension must be unique .
1560
+ 4. All member types of an Intersection type extension must not already be a
1561
+ member of the original Intersection type .
1562
+ 5. Any non -repeatable directives provided must not already apply to the original
1563
+ Intersection type .
1564
+
1418
1565
## Enums
1419
1566
1420
1567
EnumTypeDefinition :
@@ -1876,6 +2023,7 @@ TypeSystemDirectiveLocation : one of
1876
2023
- `ARGUMENT_DEFINITION `
1877
2024
- `INTERFACE `
1878
2025
- `UNION `
2026
+ - 'INTERSECTION '
1879
2027
- `ENUM `
1880
2028
- `ENUM_VALUE `
1881
2029
- `INPUT_OBJECT `
0 commit comments