@@ -43,9 +43,10 @@ type in the system, allowing the definition of arbitrary type hierarchies.
43
43
44
44
GraphQL supports two abstract types: interfaces and unions.
45
45
46
- An ` Interface ` defines a list of fields; ` Object ` types that implement that
47
- interface are guaranteed to implement those fields. Whenever the type system
48
- claims it will return an interface, it will return a valid implementing type.
46
+ An ` Interface ` defines a list of fields; ` Object ` types and other ` Interface `
47
+ types that implement the interface are guaranteed to implement those fields.
48
+ Whenever the type system claims it will return an interface, it will return a valid
49
+ implementing ` Object ` type.
49
50
50
51
A ` Union ` defines a list of possible types; similar to interfaces, whenever the
51
52
type system claims a union will be returned, one of the possible types will be
@@ -553,11 +554,15 @@ of rules must be adhered to by every Object type in a GraphQL schema.
553
554
the interface field type is either an Interface type or a Union type
554
555
and the object field type is a possible type of the interface field
555
556
type.
556
- 3 . An object field type is a valid sub-type if it is a List type and
557
+ 3 . An object field type is a valid sub-type if it is an Interface type
558
+ and the interface field type is either an Interface type or a Union
559
+ type and the object field type is a possible type of the interface
560
+ field type.
561
+ 4 . An object field type is a valid sub-type if it is a List type and
557
562
the interface field type is also a List type and the list-item type
558
563
of the object field type is a valid sub-type of the list-item type
559
564
of the interface field type.
560
- 4 . An object field type is a valid sub-type if it is a Non-Null variant
565
+ 5 . An object field type is a valid sub-type if it is a Non-Null variant
561
566
of a valid sub-type of the interface field type.
562
567
2 . The object field must include an argument of the same name for every
563
568
argument defined in the interface field.
@@ -569,9 +574,9 @@ of rules must be adhered to by every Object type in a GraphQL schema.
569
574
570
575
### Interfaces
571
576
572
- GraphQL Interfaces represent a list of named fields and their arguments. GraphQL
573
- objects can then implement an interface, which guarantees that they will
574
- contain the specified fields.
577
+ GraphQL interfaces represent a list of named fields and their arguments. GraphQL
578
+ objects and interfaces can then implement an interface, which guarantees that
579
+ they will contain the specified fields.
575
580
576
581
Fields on a GraphQL interface have the same rules as fields on a GraphQL object;
577
582
their type can be Scalar, Object, Enum, Interface, or Union, or any wrapping
@@ -652,6 +657,24 @@ interface. Querying for `age` is only valid when the result of `entity` is a
652
657
}
653
658
```
654
659
660
+ When defining an interface that implements another interface, the implementing
661
+ interface must define each field that is specified by the implemented interface.
662
+ For example, the interface ` Resource ` must define the field ` id ` to implement the
663
+ ` Node ` interface:
664
+
665
+ ``` graphql example
666
+ interface Node {
667
+ id : ID !
668
+ }
669
+
670
+ interface Resource implements Node {
671
+ id : ID !
672
+ url : String
673
+ }
674
+ ```
675
+
676
+
677
+
655
678
**Result Coercion **
656
679
657
680
The interface type should have some way of determining which object a given
@@ -672,6 +695,38 @@ Interface types have the potential to be invalid if incorrectly defined.
672
695
type ; no two fields may share the same name .
673
696
3. Each field of an Interface type must not have a name which begins with the
674
697
characters {"__" } (two underscores).
698
+ 4. An interface type may declare that it implements one or more unique
699
+ interfaces , but may not implement itself .
700
+ 5. An interface type must be a super -set of all interfaces it implements :
701
+ 1. The implementing interface type must include a field of the same name for
702
+ every field defined in an implemented interface .
703
+ 1. The implementing interface field must be of a type which is equal to or
704
+ a sub -type of the implemented interface field (covariant).
705
+ 1. An implementing interface field type is a valid sub -type if it is
706
+ equal to (the same type as) the implemented interface field type .
707
+ 2. An implementing interface field type is a valid sub -type if it is an
708
+ Object type and the implemented interface field type is either an
709
+ Interface type or a Union type and the implementing interface field
710
+ type is a possible type of the implemented interface field type .
711
+ 3. An implementing interface field type is a valid sub -type if it is an
712
+ Interface type and the implemented interface field type is either an
713
+ Interface type or a Union type and the implementing interface field
714
+ type is a possible type of the implemented interface field type .
715
+ 4. An implementing interface field type is a valid sub -type if it is a
716
+ List type and the implemented interface field type is also a List
717
+ type and the list -item type of the implementing interface field type
718
+ is a valid sub -type of the list -item type of the implemented
719
+ interface field type .
720
+ 5. An implementing interface field type is a valid sub -type if it is a
721
+ Non -Null variant of a valid sub -type of the implemented interface
722
+ field type .
723
+ 2. The implementing interface field must include an argument of the same
724
+ name for every argument defined in the implemented interface field .
725
+ 1. The implementing interface field argument must accept the same type
726
+ (invariant) as the implemented interface field argument .
727
+ 3. The implementing interface field may include additional arguments not
728
+ defined in the implemented interface field , but any additional argument
729
+ must not be required .
675
730
676
731
677
732
### Unions
0 commit comments