hydra
Search…
Algebraic types
One can construct complex types by defining unions of special non-entity type definitions decorated with @variant. The resulting complex type is mapped into JSON at the database level and should be prefixed with _json in when queried through the API. Here is an example
1
type Miserable @variant {
2
hates: String!
3
}
4
5
type HappyPoor @variant {
6
isMale: Boolean
7
}
8
9
union Poor = HappyPoor | Miserable
10
11
type MiddleClass @variant {
12
father: Poor
13
mother: Poor
14
}
15
16
type Rich @variant {
17
bank: String!
18
}
19
20
union Status = Rich | MiddleClass | HappyPoor | Miserable
21
22
type Account @entity {
23
status: Status!
24
}
Copied!
The resulting API will support inline fragments and type resolutions:
1
query {
2
accounts(limit: 5, orderBy: about_ASC, where: { status_json: { father: { isMale_eq: true }} }) {
3
about
4
status {
5
__typename
6
... on MiddleClass {
7
father {
8
... on HappyPoor {
9
isMale
10
}
11
... on Miserable {
12
hates
13
}
14
}
15
}
16
}
17
}
18
}
Copied!
Last modified 7mo ago
Copy link