-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotypes.py
102 lines (76 loc) · 2.23 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import json
from functools import cached_property
from typing import Dict, List, 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 CCRecruitment, Mails, PyObjectId, StorageFile
# 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)
)
@strawberry.experimental.pydantic.type(model=Mails, fields=["subject", "uid"])
class MailReturnType:
pass
@strawberry.experimental.pydantic.input(
model=Mails, fields=["subject", "body", "to_recipients"]
)
class MailInput:
cc_recipients: Optional[List[str]] = strawberry.UNSET
uid: Optional[str] = strawberry.UNSET
html_body: Optional[bool] = False
@strawberry.experimental.pydantic.input(
model=CCRecruitment,
# all_fields=True,
fields=[
"uid",
"email",
"teams",
"design_experience",
"why_this_position",
"why_cc",
"good_fit",
"ideas",
"other_bodies",
],
)
class CCRecruitmentInput:
pass
@strawberry.experimental.pydantic.type(model=CCRecruitment, all_fields=True)
class CCRecruitmentType:
pass
# signed url object type
@strawberry.type
class SignedURL:
url: str
@strawberry.input
class SignedURLInput:
static_file: bool = False
filename: str | None = None
max_size_mb: float = 0.3
# StorageFile Types
@strawberry.experimental.pydantic.input(
model=StorageFile, fields=["title", "filename", "filetype"]
)
class StorageFileInput:
pass
@strawberry.experimental.pydantic.type(model=StorageFile, all_fields=True)
class StorageFileType:
pass