-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathotypes.py
88 lines (66 loc) · 1.75 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
88
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 PyObjectId, User
# 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)
)
# user profile type
@strawberry.type
class ProfileType:
firstName: str
lastName: str
email: str
gender: str | None
batch: str | None
stream: str | None
rollno: str | None
# authenticated user details type
@strawberry.experimental.pydantic.type(model=User)
class UserMetaType:
uid: strawberry.auto
role: strawberry.auto
img: strawberry.auto
phone: strawberry.auto
# user input type
@strawberry.input
class UserInput:
uid: str
# user role input type
@strawberry.input
class RoleInput:
uid: str
role: str
inter_communication_secret: Optional[str] = None
# user phone input type
@strawberry.input
class PhoneInput:
uid: str
phone: str
# user data input type
@strawberry.input
class UserDataInput:
uid: str
img: Optional[str] = None
phone: Optional[str]