-
- All Implemented Interfaces:
public @interface InterfaceObjectDirective
directive @interfaceObject on OBJECT
This directive provides meta information to the router that this entity type defined within this subgraph is an interface in the supergraph. This allows you to extend functionality of an interface across the supergraph without having to implement (or even be aware of) all its implementing types.
Example: Given an interface that is defined in another subgraph
interface Product @key(fields: "id") { id: ID! description: String } type Book implements Product @key(fields: "id") { id: ID! description: String pages: Int! } type Movie implements Product @key(fields: "id") { id: ID! description: String duration: Int! }
We can extend Product entity in our subgraph and a new field directly to it. This will result in making this new field available to ALL implementing types.
@InterfaceObjectDirective data class Product(val id: ID) { fun reviews(): List<Review> = TODO() }
Which generates the following subgraph schema
type Product @key(fields: "id") @interfaceObject { id: ID! reviews: [Review!]! }