Extending interfaces
Entity interfaces
are similar to entities , but usually canβt contribute new
fields to the supergraph (see below for how to use @interfaceObject
to extend
interfaces).
Strawberry allows to define entity interfaces using the
@strawberry.federation.interface
decorator, hereβs an example:
This will generate the following GraphQL type:
Extending Entity interfaces (Apollo Federation)
In federation you can use @interfaceObject
to extend interfaces from other
services. This is useful when you want to add fields to an interface that is
implemented by types in other services.
Entity interfaces that extend other interfaces are defined by annotating an
interface with the @strawberry.federation.interface_object
decorator, like in
example below:
This will generate the following GraphQL type:
@strawberry.federation.interface_object
is necessary because if we were to
extend the Media
interface using @strawberry.federation.interface
, weβd need
to also define all the types implementing the interface, which will make the
schema hard to maintain (every updated to the interface and types implementing
it would need to be reflected in all subgraphs declaring it).
Resolving references
Entity interfaces are also used to resolve references to entities. The same rules as entities apply here. Hereβs a basic example: