hydra
Search…
Interfaces
Extract interfaces and query multiple types in a single query
Interfaces are useful when several entity types share some set of properties and one would like to have an aggregated result when such a common property is queried.
This is achieved through the natively supported GraphQL interface type and inline fragments in the output schema. For example, let us define the following input schema:
1
interface Profile @entity {
2
about: String!
3
}
4
5
type Member implements Profile @entity {
6
about: String!
7
handle: String!
8
}
9
10
type Account implements Profile @entity {
11
about: String!
12
accountId: Bytes
13
}
Copied!
Note that interfaces should be decorated with @entity and all the subclasses must explicitly define the inherited fields (otherwise an error will be thrown during the codegen).
The output schema will support a query by about which puts together Member and Account types. Note that orderBy is also supported for the inherited properties as well as OpenCRUD.
1
query {
2
profiles(limit: 5, offset: 5, orderBy: about_ASC, where: { about_eq: "joystreamer" }) {
3
about
4
__typename
5
... on Member {
6
handle
7
}
8
... on Account {
9
accountId
10
}
11
}
12
}
Copied!
Last modified 8mo ago
Copy link