-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathschema.py
61 lines (42 loc) · 1.22 KB
/
schema.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from graphql.core.type.definition import GraphQLArgument
from epoxy.registry import TypeRegistry
import enum
R = TypeRegistry()
@R.Register
class Episode(enum.Enum):
NEWHOPE = 4
EMPIRE = 5
JEDI = 6
class Character(R.Interface):
id = R.String.NonNull
name = R.String
friends = R.Character.List
appears_in = R.Episode.List
def resolve_friends(self, obj, args, info):
from .data import get_friends
return get_friends(obj)
class Human(R.Implements.Character):
home_planet = R.String
class Droid(R.Implements.Character):
primary_function = R.String
class Query(R.ObjectType):
# Args API will change.
hero = R.Character(args={
'episode': R.Episode
})
human = R.Human(args={
'id': R.String
})
droid = R.Droid(args={
'id': R.String
})
def resolve_hero(self, obj, args, info):
from .data import get_hero
return get_hero(args.get('episode'))
def resolve_human(self, obj, args, info):
from .data import get_human
return get_human(args['id'])
def resolve_droid(self, obj, args, info):
from .data import get_droid
return get_droid(args['id'])
StarWarsSchema = R.Schema(R.Query)