Skip to content

Commit 913b244

Browse files
committed
RFC: Allow interfaces to implement other interfaces
1 parent 951971b commit 913b244

File tree

1 file changed

+63
-8
lines changed

1 file changed

+63
-8
lines changed

spec/Section 3 -- Type System.md

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ type in the system, allowing the definition of arbitrary type hierarchies.
4343

4444
GraphQL supports two abstract types: interfaces and unions.
4545

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.
4950

5051
A `Union` defines a list of possible types; similar to interfaces, whenever the
5152
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.
553554
the interface field type is either an Interface type or a Union type
554555
and the object field type is a possible type of the interface field
555556
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
557562
the interface field type is also a List type and the list-item type
558563
of the object field type is a valid sub-type of the list-item type
559564
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
561566
of a valid sub-type of the interface field type.
562567
2. The object field must include an argument of the same name for every
563568
argument defined in the interface field.
@@ -569,9 +574,9 @@ of rules must be adhered to by every Object type in a GraphQL schema.
569574

570575
### Interfaces
571576

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.
575580

576581
Fields on a GraphQL interface have the same rules as fields on a GraphQL object;
577582
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
652657
}
653658
```
654659

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+
655678
**Result Coercion**
656679

657680
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.
672695
type; no two fields may share the same name.
673696
3. Each field of an Interface type must not have a name which begins with the
674697
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.
675730

676731

677732
### Unions

0 commit comments

Comments
 (0)