-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathotypes.py
87 lines (65 loc) · 1.72 KB
/
otypes.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import json
from functools import cached_property
from typing import Dict, Optional, Union
import strawberry
from strawberry.fastapi import BaseContext
from strawberry.types import Info as _Info
from strawberry.types.info import RootValueType
from models import Member, PyObjectId, Roles
# custom context class
class Context(BaseContext):
@cached_property
def user(self) -> Union[Dict, None]:
if not self.request:
return None
user = json.loads(self.request.headers.get("user", "{}"))
return user
@cached_property
def cookies(self) -> Union[Dict, None]:
if not self.request:
return None
cookies = json.loads(self.request.headers.get("cookies", "{}"))
return cookies
# custom info type
Info = _Info[Context, RootValueType]
# serialize PyObjectId as a scalar type
PyObjectIdType = strawberry.scalar(
PyObjectId, serialize=str, parse_value=lambda v: PyObjectId(v)
)
# TYPES
@strawberry.experimental.pydantic.type(model=Roles, all_fields=True)
class RolesType:
pass
@strawberry.experimental.pydantic.type(
model=Member,
fields=[
"id",
"cid",
"uid",
"roles",
"poc",
"creation_time",
"last_edited_time",
],
)
class MemberType:
pass
# INPUTS
@strawberry.experimental.pydantic.input(
model=Roles, fields=["name", "start_year", "end_year"]
)
class RolesInput:
pass
@strawberry.experimental.pydantic.input(
model=Member, fields=["cid", "uid", "roles"]
)
class FullMemberInput:
poc: Optional[bool] = strawberry.UNSET
@strawberry.input
class SimpleMemberInput:
cid: str
uid: str
rid: Optional[str]
@strawberry.input
class SimpleClubInput:
cid: str