-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
relay_node.py
47 lines (34 loc) · 897 Bytes
/
relay_node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from dataclasses import dataclass
from uuid import UUID
import graphql
from graphql.utilities import print_schema
from apischema.graphql import graphql_schema, relay
@dataclass
class Ship(relay.Node[UUID]): # Let's use an UUID for Ship id
name: str
@classmethod
async def get_by_id(cls, id: UUID, info: graphql.GraphQLResolveInfo = None):
...
@dataclass
class Faction(relay.Node[int]): # Nodes can have different id types
name: str
@classmethod
def get_by_id(cls, id: int, info: graphql.GraphQLResolveInfo = None) -> "Faction":
...
schema = graphql_schema(query=[relay.node], types=relay.nodes())
schema_str = """\
type Ship implements Node {
id: ID!
name: String!
}
interface Node {
id: ID!
}
type Faction implements Node {
id: ID!
name: String!
}
type Query {
node(id: ID!): Node!
}"""
assert print_schema(schema) == schema_str