forked from dvndrsn/graphql-python-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharacter.py
More file actions
34 lines (22 loc) · 982 Bytes
/
character.py
File metadata and controls
34 lines (22 loc) · 982 Bytes
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
from typing import Any, List, Optional
import graphene
from promise import Promise
from story.models import Character, Passage
class CharacterType(graphene.ObjectType):
class Meta:
interfaces = (graphene.Node, )
name = graphene.String()
in_passages = graphene.ConnectionField('api.query.passage.PassageConnection')
@staticmethod
def resolve_in_passages(root: Character, info: graphene.ResolveInfo,
**kwargs) -> Promise[List[Passage]]:
return info.context.loaders.passage_from_pov_character.load(root.id)
@classmethod
def is_type_of(cls, root: Any, info: graphene.ResolveInfo) -> bool:
return isinstance(root, Character)
@classmethod
def get_node(cls, info: graphene.ResolveInfo, decoded_id: str) -> Promise[Optional[Character]]:
key = int(decoded_id)
return info.context.loaders.character.load(key)
class Query(graphene.ObjectType):
node = graphene.Node.Field()