strawberry-graphql 0.221.0.dev1710955937__py3-none-any.whl → 0.222.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- strawberry/__init__.py +2 -0
- strawberry/federation/enum.py +37 -4
- strawberry/federation/field.py +53 -24
- strawberry/federation/object_type.py +81 -27
- strawberry/federation/scalar.py +26 -1
- strawberry/federation/schema_directives.py +70 -12
- strawberry/field_extensions/input_mutation.py +1 -1
- strawberry/schema_codegen/__init__.py +15 -196
- strawberry/types/fields/resolver.py +1 -1
- strawberry/types/info.py +19 -3
- {strawberry_graphql-0.221.0.dev1710955937.dist-info → strawberry_graphql-0.222.0.dist-info}/METADATA +1 -1
- {strawberry_graphql-0.221.0.dev1710955937.dist-info → strawberry_graphql-0.222.0.dist-info}/RECORD +15 -15
- {strawberry_graphql-0.221.0.dev1710955937.dist-info → strawberry_graphql-0.222.0.dist-info}/LICENSE +0 -0
- {strawberry_graphql-0.221.0.dev1710955937.dist-info → strawberry_graphql-0.222.0.dist-info}/WHEEL +0 -0
- {strawberry_graphql-0.221.0.dev1710955937.dist-info → strawberry_graphql-0.222.0.dist-info}/entry_points.txt +0 -0
strawberry/__init__.py
CHANGED
@@ -14,6 +14,7 @@ from .private import Private
|
|
14
14
|
from .scalars import ID
|
15
15
|
from .schema import Schema
|
16
16
|
from .schema_directive import schema_directive
|
17
|
+
from .types.info import Info
|
17
18
|
from .union import union
|
18
19
|
from .unset import UNSET
|
19
20
|
|
@@ -21,6 +22,7 @@ __all__ = [
|
|
21
22
|
"BasePermission",
|
22
23
|
"experimental",
|
23
24
|
"ID",
|
25
|
+
"Info",
|
24
26
|
"UNSET",
|
25
27
|
"lazy",
|
26
28
|
"LazyType",
|
strawberry/federation/enum.py
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from typing import
|
3
|
+
from typing import (
|
4
|
+
TYPE_CHECKING,
|
5
|
+
Any,
|
6
|
+
Callable,
|
7
|
+
Iterable,
|
8
|
+
List,
|
9
|
+
Optional,
|
10
|
+
Union,
|
11
|
+
overload,
|
12
|
+
)
|
4
13
|
|
5
14
|
from strawberry.enum import _process_enum
|
6
15
|
from strawberry.enum import enum_value as base_enum_value
|
@@ -36,7 +45,10 @@ def enum(
|
|
36
45
|
name: Optional[str] = None,
|
37
46
|
description: Optional[str] = None,
|
38
47
|
directives: Iterable[object] = (),
|
48
|
+
authenticated: bool = False,
|
39
49
|
inaccessible: bool = False,
|
50
|
+
policy: Optional[List[List[str]]] = None,
|
51
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
40
52
|
tags: Optional[Iterable[str]] = (),
|
41
53
|
) -> EnumType:
|
42
54
|
...
|
@@ -49,7 +61,10 @@ def enum(
|
|
49
61
|
name: Optional[str] = None,
|
50
62
|
description: Optional[str] = None,
|
51
63
|
directives: Iterable[object] = (),
|
64
|
+
authenticated: bool = False,
|
52
65
|
inaccessible: bool = False,
|
66
|
+
policy: Optional[List[List[str]]] = None,
|
67
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
53
68
|
tags: Optional[Iterable[str]] = (),
|
54
69
|
) -> Callable[[EnumType], EnumType]:
|
55
70
|
...
|
@@ -61,8 +76,11 @@ def enum(
|
|
61
76
|
name=None,
|
62
77
|
description=None,
|
63
78
|
directives=(),
|
64
|
-
|
65
|
-
|
79
|
+
authenticated: bool = False,
|
80
|
+
inaccessible: bool = False,
|
81
|
+
policy: Optional[List[List[str]]] = None,
|
82
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
83
|
+
tags: Optional[Iterable[str]] = (),
|
66
84
|
) -> Union[EnumType, Callable[[EnumType], EnumType]]:
|
67
85
|
"""Registers the enum in the GraphQL type system.
|
68
86
|
|
@@ -70,13 +88,28 @@ def enum(
|
|
70
88
|
the value passed of name instead of the Enum class name.
|
71
89
|
"""
|
72
90
|
|
73
|
-
from strawberry.federation.schema_directives import
|
91
|
+
from strawberry.federation.schema_directives import (
|
92
|
+
Authenticated,
|
93
|
+
Inaccessible,
|
94
|
+
Policy,
|
95
|
+
RequiresScopes,
|
96
|
+
Tag,
|
97
|
+
)
|
74
98
|
|
75
99
|
directives = list(directives)
|
76
100
|
|
101
|
+
if authenticated:
|
102
|
+
directives.append(Authenticated())
|
103
|
+
|
77
104
|
if inaccessible:
|
78
105
|
directives.append(Inaccessible())
|
79
106
|
|
107
|
+
if policy:
|
108
|
+
directives.append(Policy(policies=policy))
|
109
|
+
|
110
|
+
if requires_scopes:
|
111
|
+
directives.append(RequiresScopes(scopes=requires_scopes))
|
112
|
+
|
80
113
|
if tags:
|
81
114
|
directives.extend(Tag(name=tag) for tag in tags)
|
82
115
|
|
strawberry/federation/field.py
CHANGED
@@ -25,6 +25,7 @@ if TYPE_CHECKING:
|
|
25
25
|
from strawberry.field import _RESOLVER_TYPE, StrawberryField
|
26
26
|
from strawberry.permission import BasePermission
|
27
27
|
|
28
|
+
from .schema_directives import Override
|
28
29
|
|
29
30
|
T = TypeVar("T")
|
30
31
|
|
@@ -36,13 +37,16 @@ def field(
|
|
36
37
|
name: Optional[str] = None,
|
37
38
|
is_subscription: bool = False,
|
38
39
|
description: Optional[str] = None,
|
40
|
+
authenticated: bool = False,
|
41
|
+
external: bool = False,
|
42
|
+
inaccessible: bool = False,
|
43
|
+
policy: Optional[List[List[str]]] = None,
|
39
44
|
provides: Optional[List[str]] = None,
|
45
|
+
override: Optional[Union[Override, str]] = None,
|
40
46
|
requires: Optional[List[str]] = None,
|
41
|
-
|
42
|
-
shareable: bool = False,
|
47
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
43
48
|
tags: Optional[Iterable[str]] = (),
|
44
|
-
|
45
|
-
inaccessible: bool = False,
|
49
|
+
shareable: bool = False,
|
46
50
|
init: Literal[False] = False,
|
47
51
|
permission_classes: Optional[List[Type[BasePermission]]] = None,
|
48
52
|
deprecation_reason: Optional[str] = None,
|
@@ -61,13 +65,16 @@ def field(
|
|
61
65
|
name: Optional[str] = None,
|
62
66
|
is_subscription: bool = False,
|
63
67
|
description: Optional[str] = None,
|
68
|
+
authenticated: bool = False,
|
69
|
+
external: bool = False,
|
70
|
+
inaccessible: bool = False,
|
71
|
+
policy: Optional[List[List[str]]] = None,
|
64
72
|
provides: Optional[List[str]] = None,
|
73
|
+
override: Optional[Union[Override, str]] = None,
|
65
74
|
requires: Optional[List[str]] = None,
|
66
|
-
|
67
|
-
shareable: bool = False,
|
75
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
68
76
|
tags: Optional[Iterable[str]] = (),
|
69
|
-
|
70
|
-
inaccessible: bool = False,
|
77
|
+
shareable: bool = False,
|
71
78
|
init: Literal[True] = True,
|
72
79
|
permission_classes: Optional[List[Type[BasePermission]]] = None,
|
73
80
|
deprecation_reason: Optional[str] = None,
|
@@ -87,13 +94,16 @@ def field(
|
|
87
94
|
name: Optional[str] = None,
|
88
95
|
is_subscription: bool = False,
|
89
96
|
description: Optional[str] = None,
|
97
|
+
authenticated: bool = False,
|
98
|
+
external: bool = False,
|
99
|
+
inaccessible: bool = False,
|
100
|
+
policy: Optional[List[List[str]]] = None,
|
90
101
|
provides: Optional[List[str]] = None,
|
102
|
+
override: Optional[Union[Override, str]] = None,
|
91
103
|
requires: Optional[List[str]] = None,
|
92
|
-
|
93
|
-
shareable: bool = False,
|
104
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
94
105
|
tags: Optional[Iterable[str]] = (),
|
95
|
-
|
96
|
-
inaccessible: bool = False,
|
106
|
+
shareable: bool = False,
|
97
107
|
permission_classes: Optional[List[Type[BasePermission]]] = None,
|
98
108
|
deprecation_reason: Optional[str] = None,
|
99
109
|
default: Any = UNSET,
|
@@ -111,13 +121,16 @@ def field(
|
|
111
121
|
name: Optional[str] = None,
|
112
122
|
is_subscription: bool = False,
|
113
123
|
description: Optional[str] = None,
|
124
|
+
authenticated: bool = False,
|
125
|
+
external: bool = False,
|
126
|
+
inaccessible: bool = False,
|
127
|
+
policy: Optional[List[List[str]]] = None,
|
114
128
|
provides: Optional[List[str]] = None,
|
129
|
+
override: Optional[Union[Override, str]] = None,
|
115
130
|
requires: Optional[List[str]] = None,
|
116
|
-
|
117
|
-
shareable: bool = False,
|
131
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
118
132
|
tags: Optional[Iterable[str]] = (),
|
119
|
-
|
120
|
-
inaccessible: bool = False,
|
133
|
+
shareable: bool = False,
|
121
134
|
permission_classes: Optional[List[Type[BasePermission]]] = None,
|
122
135
|
deprecation_reason: Optional[str] = None,
|
123
136
|
default: Any = dataclasses.MISSING,
|
@@ -131,25 +144,47 @@ def field(
|
|
131
144
|
init: Literal[True, False, None] = None,
|
132
145
|
) -> Any:
|
133
146
|
from .schema_directives import (
|
147
|
+
Authenticated,
|
134
148
|
External,
|
135
149
|
Inaccessible,
|
136
150
|
Override,
|
151
|
+
Policy,
|
137
152
|
Provides,
|
138
153
|
Requires,
|
154
|
+
RequiresScopes,
|
139
155
|
Shareable,
|
140
156
|
Tag,
|
141
157
|
)
|
142
158
|
|
143
159
|
directives = list(directives)
|
144
160
|
|
161
|
+
if authenticated:
|
162
|
+
directives.append(Authenticated())
|
163
|
+
|
164
|
+
if external:
|
165
|
+
directives.append(External())
|
166
|
+
|
167
|
+
if inaccessible:
|
168
|
+
directives.append(Inaccessible())
|
169
|
+
|
170
|
+
if override:
|
171
|
+
directives.append(
|
172
|
+
Override(override_from=override, label=UNSET)
|
173
|
+
if isinstance(override, str)
|
174
|
+
else override
|
175
|
+
)
|
176
|
+
|
177
|
+
if policy:
|
178
|
+
directives.append(Policy(policies=policy))
|
179
|
+
|
145
180
|
if provides:
|
146
181
|
directives.append(Provides(fields=" ".join(provides)))
|
147
182
|
|
148
183
|
if requires:
|
149
184
|
directives.append(Requires(fields=" ".join(requires)))
|
150
185
|
|
151
|
-
if
|
152
|
-
directives.append(
|
186
|
+
if requires_scopes:
|
187
|
+
directives.append(RequiresScopes(scopes=requires_scopes))
|
153
188
|
|
154
189
|
if shareable:
|
155
190
|
directives.append(Shareable())
|
@@ -157,12 +192,6 @@ def field(
|
|
157
192
|
if tags:
|
158
193
|
directives.extend(Tag(name=tag) for tag in tags)
|
159
194
|
|
160
|
-
if override:
|
161
|
-
directives.append(Override(override_from=override))
|
162
|
-
|
163
|
-
if inaccessible:
|
164
|
-
directives.append(Inaccessible())
|
165
|
-
|
166
195
|
return base_field( # type: ignore
|
167
196
|
resolver=resolver, # type: ignore
|
168
197
|
name=name,
|
@@ -2,6 +2,7 @@ from typing import (
|
|
2
2
|
TYPE_CHECKING,
|
3
3
|
Callable,
|
4
4
|
Iterable,
|
5
|
+
List,
|
5
6
|
Optional,
|
6
7
|
Sequence,
|
7
8
|
Type,
|
@@ -31,19 +32,25 @@ def _impl_type(
|
|
31
32
|
name: Optional[str] = None,
|
32
33
|
description: Optional[str] = None,
|
33
34
|
directives: Iterable[object] = (),
|
35
|
+
authenticated: bool = False,
|
34
36
|
keys: Iterable[Union["Key", str]] = (),
|
35
37
|
extend: bool = False,
|
36
38
|
shareable: bool = False,
|
37
39
|
inaccessible: bool = UNSET,
|
40
|
+
policy: Optional[List[List[str]]] = None,
|
41
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
38
42
|
tags: Iterable[str] = (),
|
39
43
|
is_input: bool = False,
|
40
44
|
is_interface: bool = False,
|
41
45
|
is_interface_object: bool = False,
|
42
46
|
) -> T:
|
43
47
|
from strawberry.federation.schema_directives import (
|
48
|
+
Authenticated,
|
44
49
|
Inaccessible,
|
45
50
|
InterfaceObject,
|
46
51
|
Key,
|
52
|
+
Policy,
|
53
|
+
RequiresScopes,
|
47
54
|
Shareable,
|
48
55
|
Tag,
|
49
56
|
)
|
@@ -55,12 +62,21 @@ def _impl_type(
|
|
55
62
|
for key in keys
|
56
63
|
)
|
57
64
|
|
58
|
-
if
|
59
|
-
directives.append(
|
65
|
+
if authenticated:
|
66
|
+
directives.append(Authenticated())
|
60
67
|
|
61
68
|
if inaccessible is not UNSET:
|
62
69
|
directives.append(Inaccessible())
|
63
70
|
|
71
|
+
if policy:
|
72
|
+
directives.append(Policy(policies=policy))
|
73
|
+
|
74
|
+
if requires_scopes:
|
75
|
+
directives.append(RequiresScopes(scopes=requires_scopes))
|
76
|
+
|
77
|
+
if shareable:
|
78
|
+
directives.append(Shareable())
|
79
|
+
|
64
80
|
if tags:
|
65
81
|
directives.extend(Tag(name=tag) for tag in tags)
|
66
82
|
|
@@ -89,10 +105,15 @@ def type(
|
|
89
105
|
*,
|
90
106
|
name: Optional[str] = None,
|
91
107
|
description: Optional[str] = None,
|
92
|
-
|
108
|
+
directives: Iterable[object] = (),
|
109
|
+
authenticated: bool = False,
|
110
|
+
extend: bool = False,
|
93
111
|
inaccessible: bool = UNSET,
|
112
|
+
keys: Iterable[Union["Key", str]] = (),
|
113
|
+
policy: Optional[List[List[str]]] = None,
|
114
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
115
|
+
shareable: bool = False,
|
94
116
|
tags: Iterable[str] = (),
|
95
|
-
extend: bool = False,
|
96
117
|
) -> T:
|
97
118
|
...
|
98
119
|
|
@@ -107,12 +128,15 @@ def type(
|
|
107
128
|
*,
|
108
129
|
name: Optional[str] = None,
|
109
130
|
description: Optional[str] = None,
|
110
|
-
|
111
|
-
|
112
|
-
tags: Iterable[str] = (),
|
131
|
+
directives: Iterable[object] = (),
|
132
|
+
authenticated: bool = False,
|
113
133
|
extend: bool = False,
|
134
|
+
inaccessible: bool = UNSET,
|
135
|
+
keys: Iterable[Union["Key", str]] = (),
|
136
|
+
policy: Optional[List[List[str]]] = None,
|
137
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
114
138
|
shareable: bool = False,
|
115
|
-
|
139
|
+
tags: Iterable[str] = (),
|
116
140
|
) -> Callable[[T], T]:
|
117
141
|
...
|
118
142
|
|
@@ -122,22 +146,28 @@ def type(
|
|
122
146
|
*,
|
123
147
|
name: Optional[str] = None,
|
124
148
|
description: Optional[str] = None,
|
125
|
-
|
126
|
-
|
127
|
-
tags: Iterable[str] = (),
|
149
|
+
directives: Iterable[object] = (),
|
150
|
+
authenticated: bool = False,
|
128
151
|
extend: bool = False,
|
152
|
+
inaccessible: bool = UNSET,
|
153
|
+
keys: Iterable[Union["Key", str]] = (),
|
154
|
+
policy: Optional[List[List[str]]] = None,
|
155
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
129
156
|
shareable: bool = False,
|
130
|
-
|
157
|
+
tags: Iterable[str] = (),
|
131
158
|
):
|
132
159
|
return _impl_type(
|
133
160
|
cls,
|
134
161
|
name=name,
|
135
162
|
description=description,
|
136
163
|
directives=directives,
|
164
|
+
authenticated=authenticated,
|
137
165
|
keys=keys,
|
138
166
|
extend=extend,
|
139
|
-
shareable=shareable,
|
140
167
|
inaccessible=inaccessible,
|
168
|
+
policy=policy,
|
169
|
+
requires_scopes=requires_scopes,
|
170
|
+
shareable=shareable,
|
141
171
|
tags=tags,
|
142
172
|
)
|
143
173
|
|
@@ -208,10 +238,13 @@ def interface(
|
|
208
238
|
*,
|
209
239
|
name: Optional[str] = None,
|
210
240
|
description: Optional[str] = None,
|
211
|
-
|
241
|
+
directives: Iterable[object] = (),
|
242
|
+
authenticated: bool = False,
|
212
243
|
inaccessible: bool = UNSET,
|
244
|
+
keys: Iterable[Union["Key", str]] = (),
|
245
|
+
policy: Optional[List[List[str]]] = None,
|
246
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
213
247
|
tags: Iterable[str] = (),
|
214
|
-
directives: Iterable[object] = (),
|
215
248
|
) -> T:
|
216
249
|
...
|
217
250
|
|
@@ -226,10 +259,13 @@ def interface(
|
|
226
259
|
*,
|
227
260
|
name: Optional[str] = None,
|
228
261
|
description: Optional[str] = None,
|
229
|
-
|
262
|
+
directives: Iterable[object] = (),
|
263
|
+
authenticated: bool = False,
|
230
264
|
inaccessible: bool = UNSET,
|
265
|
+
keys: Iterable[Union["Key", str]] = (),
|
266
|
+
policy: Optional[List[List[str]]] = None,
|
267
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
231
268
|
tags: Iterable[str] = (),
|
232
|
-
directives: Iterable[object] = (),
|
233
269
|
) -> Callable[[T], T]:
|
234
270
|
...
|
235
271
|
|
@@ -239,20 +275,26 @@ def interface(
|
|
239
275
|
*,
|
240
276
|
name: Optional[str] = None,
|
241
277
|
description: Optional[str] = None,
|
242
|
-
|
278
|
+
directives: Iterable[object] = (),
|
279
|
+
authenticated: bool = False,
|
243
280
|
inaccessible: bool = UNSET,
|
281
|
+
keys: Iterable[Union["Key", str]] = (),
|
282
|
+
policy: Optional[List[List[str]]] = None,
|
283
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
244
284
|
tags: Iterable[str] = (),
|
245
|
-
directives: Iterable[object] = (),
|
246
285
|
):
|
247
286
|
return _impl_type(
|
248
287
|
cls,
|
249
288
|
name=name,
|
250
289
|
description=description,
|
251
290
|
directives=directives,
|
291
|
+
authenticated=authenticated,
|
252
292
|
keys=keys,
|
253
293
|
inaccessible=inaccessible,
|
254
|
-
|
294
|
+
policy=policy,
|
295
|
+
requires_scopes=requires_scopes,
|
255
296
|
tags=tags,
|
297
|
+
is_interface=True,
|
256
298
|
)
|
257
299
|
|
258
300
|
|
@@ -265,12 +307,15 @@ def interface(
|
|
265
307
|
def interface_object(
|
266
308
|
cls: T,
|
267
309
|
*,
|
268
|
-
keys: Iterable[Union["Key", str]],
|
269
310
|
name: Optional[str] = None,
|
270
311
|
description: Optional[str] = None,
|
312
|
+
directives: Iterable[object] = (),
|
313
|
+
authenticated: bool = False,
|
271
314
|
inaccessible: bool = UNSET,
|
315
|
+
keys: Iterable[Union["Key", str]] = (),
|
316
|
+
policy: Optional[List[List[str]]] = None,
|
317
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
272
318
|
tags: Iterable[str] = (),
|
273
|
-
directives: Iterable[object] = (),
|
274
319
|
) -> T:
|
275
320
|
...
|
276
321
|
|
@@ -283,12 +328,15 @@ def interface_object(
|
|
283
328
|
)
|
284
329
|
def interface_object(
|
285
330
|
*,
|
286
|
-
keys: Iterable[Union["Key", str]],
|
287
331
|
name: Optional[str] = None,
|
288
332
|
description: Optional[str] = None,
|
333
|
+
directives: Iterable[object] = (),
|
334
|
+
authenticated: bool = False,
|
289
335
|
inaccessible: bool = UNSET,
|
336
|
+
keys: Iterable[Union["Key", str]] = (),
|
337
|
+
policy: Optional[List[List[str]]] = None,
|
338
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
290
339
|
tags: Iterable[str] = (),
|
291
|
-
directives: Iterable[object] = (),
|
292
340
|
) -> Callable[[T], T]:
|
293
341
|
...
|
294
342
|
|
@@ -296,21 +344,27 @@ def interface_object(
|
|
296
344
|
def interface_object(
|
297
345
|
cls: Optional[T] = None,
|
298
346
|
*,
|
299
|
-
keys: Iterable[Union["Key", str]],
|
300
347
|
name: Optional[str] = None,
|
301
348
|
description: Optional[str] = None,
|
349
|
+
directives: Iterable[object] = (),
|
350
|
+
authenticated: bool = False,
|
302
351
|
inaccessible: bool = UNSET,
|
352
|
+
keys: Iterable[Union["Key", str]] = (),
|
353
|
+
policy: Optional[List[List[str]]] = None,
|
354
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
303
355
|
tags: Iterable[str] = (),
|
304
|
-
directives: Iterable[object] = (),
|
305
356
|
):
|
306
357
|
return _impl_type(
|
307
358
|
cls,
|
308
359
|
name=name,
|
309
360
|
description=description,
|
310
361
|
directives=directives,
|
362
|
+
authenticated=authenticated,
|
311
363
|
keys=keys,
|
312
364
|
inaccessible=inaccessible,
|
365
|
+
policy=policy,
|
366
|
+
requires_scopes=requires_scopes,
|
367
|
+
tags=tags,
|
313
368
|
is_interface=False,
|
314
369
|
is_interface_object=True,
|
315
|
-
tags=tags,
|
316
370
|
)
|
strawberry/federation/scalar.py
CHANGED
@@ -3,6 +3,7 @@ from typing import (
|
|
3
3
|
Any,
|
4
4
|
Callable,
|
5
5
|
Iterable,
|
6
|
+
List,
|
6
7
|
NewType,
|
7
8
|
Optional,
|
8
9
|
Type,
|
@@ -34,7 +35,10 @@ def scalar(
|
|
34
35
|
parse_value: Optional[Callable] = None,
|
35
36
|
parse_literal: Optional[Callable] = None,
|
36
37
|
directives: Iterable[object] = (),
|
38
|
+
authenticated: bool = False,
|
37
39
|
inaccessible: bool = False,
|
40
|
+
policy: Optional[List[List[str]]] = None,
|
41
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
38
42
|
tags: Optional[Iterable[str]] = (),
|
39
43
|
) -> Callable[[_T], _T]:
|
40
44
|
...
|
@@ -51,7 +55,10 @@ def scalar(
|
|
51
55
|
parse_value: Optional[Callable] = None,
|
52
56
|
parse_literal: Optional[Callable] = None,
|
53
57
|
directives: Iterable[object] = (),
|
58
|
+
authenticated: bool = False,
|
54
59
|
inaccessible: bool = False,
|
60
|
+
policy: Optional[List[List[str]]] = None,
|
61
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
55
62
|
tags: Optional[Iterable[str]] = (),
|
56
63
|
) -> _T:
|
57
64
|
...
|
@@ -67,7 +74,10 @@ def scalar(
|
|
67
74
|
parse_value: Optional[Callable] = None,
|
68
75
|
parse_literal: Optional[Callable] = None,
|
69
76
|
directives: Iterable[object] = (),
|
77
|
+
authenticated: bool = False,
|
70
78
|
inaccessible: bool = False,
|
79
|
+
policy: Optional[List[List[str]]] = None,
|
80
|
+
requires_scopes: Optional[List[List[str]]] = None,
|
71
81
|
tags: Optional[Iterable[str]] = (),
|
72
82
|
) -> Any:
|
73
83
|
"""Annotates a class or type as a GraphQL custom scalar.
|
@@ -95,16 +105,31 @@ def scalar(
|
|
95
105
|
>>> self.items = items
|
96
106
|
|
97
107
|
"""
|
98
|
-
from strawberry.federation.schema_directives import
|
108
|
+
from strawberry.federation.schema_directives import (
|
109
|
+
Authenticated,
|
110
|
+
Inaccessible,
|
111
|
+
Policy,
|
112
|
+
RequiresScopes,
|
113
|
+
Tag,
|
114
|
+
)
|
99
115
|
|
100
116
|
if parse_value is None:
|
101
117
|
parse_value = cls
|
102
118
|
|
103
119
|
directives = list(directives)
|
104
120
|
|
121
|
+
if authenticated:
|
122
|
+
directives.append(Authenticated())
|
123
|
+
|
105
124
|
if inaccessible:
|
106
125
|
directives.append(Inaccessible())
|
107
126
|
|
127
|
+
if policy:
|
128
|
+
directives.append(Policy(policies=policy))
|
129
|
+
|
130
|
+
if requires_scopes:
|
131
|
+
directives.append(RequiresScopes(scopes=requires_scopes))
|
132
|
+
|
108
133
|
if tags:
|
109
134
|
directives.extend(Tag(name=tag) for tag in tags)
|
110
135
|
|
@@ -5,13 +5,17 @@ from strawberry import directive_field
|
|
5
5
|
from strawberry.schema_directive import Location, schema_directive
|
6
6
|
from strawberry.unset import UNSET
|
7
7
|
|
8
|
-
from .types import
|
8
|
+
from .types import (
|
9
|
+
FieldSet,
|
10
|
+
LinkImport,
|
11
|
+
LinkPurpose,
|
12
|
+
)
|
9
13
|
|
10
14
|
|
11
15
|
@dataclass
|
12
16
|
class ImportedFrom:
|
13
17
|
name: str
|
14
|
-
url: str = "https://specs.apollo.dev/federation/v2.
|
18
|
+
url: str = "https://specs.apollo.dev/federation/v2.7"
|
15
19
|
|
16
20
|
|
17
21
|
class FederationDirective:
|
@@ -23,7 +27,7 @@ class FederationDirective:
|
|
23
27
|
)
|
24
28
|
class External(FederationDirective):
|
25
29
|
imported_from: ClassVar[ImportedFrom] = ImportedFrom(
|
26
|
-
name="external", url="https://specs.apollo.dev/federation/v2.
|
30
|
+
name="external", url="https://specs.apollo.dev/federation/v2.7"
|
27
31
|
)
|
28
32
|
|
29
33
|
|
@@ -33,7 +37,7 @@ class External(FederationDirective):
|
|
33
37
|
class Requires(FederationDirective):
|
34
38
|
fields: FieldSet
|
35
39
|
imported_from: ClassVar[ImportedFrom] = ImportedFrom(
|
36
|
-
name="requires", url="https://specs.apollo.dev/federation/v2.
|
40
|
+
name="requires", url="https://specs.apollo.dev/federation/v2.7"
|
37
41
|
)
|
38
42
|
|
39
43
|
|
@@ -43,7 +47,7 @@ class Requires(FederationDirective):
|
|
43
47
|
class Provides(FederationDirective):
|
44
48
|
fields: FieldSet
|
45
49
|
imported_from: ClassVar[ImportedFrom] = ImportedFrom(
|
46
|
-
name="provides", url="https://specs.apollo.dev/federation/v2.
|
50
|
+
name="provides", url="https://specs.apollo.dev/federation/v2.7"
|
47
51
|
)
|
48
52
|
|
49
53
|
|
@@ -57,7 +61,7 @@ class Key(FederationDirective):
|
|
57
61
|
fields: FieldSet
|
58
62
|
resolvable: Optional[bool] = True
|
59
63
|
imported_from: ClassVar[ImportedFrom] = ImportedFrom(
|
60
|
-
name="key", url="https://specs.apollo.dev/federation/v2.
|
64
|
+
name="key", url="https://specs.apollo.dev/federation/v2.7"
|
61
65
|
)
|
62
66
|
|
63
67
|
|
@@ -69,7 +73,7 @@ class Key(FederationDirective):
|
|
69
73
|
)
|
70
74
|
class Shareable(FederationDirective):
|
71
75
|
imported_from: ClassVar[ImportedFrom] = ImportedFrom(
|
72
|
-
name="shareable", url="https://specs.apollo.dev/federation/v2.
|
76
|
+
name="shareable", url="https://specs.apollo.dev/federation/v2.7"
|
73
77
|
)
|
74
78
|
|
75
79
|
|
@@ -115,7 +119,7 @@ class Link:
|
|
115
119
|
class Tag(FederationDirective):
|
116
120
|
name: str
|
117
121
|
imported_from: ClassVar[ImportedFrom] = ImportedFrom(
|
118
|
-
name="tag", url="https://specs.apollo.dev/federation/v2.
|
122
|
+
name="tag", url="https://specs.apollo.dev/federation/v2.7"
|
119
123
|
)
|
120
124
|
|
121
125
|
|
@@ -124,8 +128,9 @@ class Tag(FederationDirective):
|
|
124
128
|
)
|
125
129
|
class Override(FederationDirective):
|
126
130
|
override_from: str = directive_field(name="from")
|
131
|
+
label: Optional[str] = UNSET
|
127
132
|
imported_from: ClassVar[ImportedFrom] = ImportedFrom(
|
128
|
-
name="override", url="https://specs.apollo.dev/federation/v2.
|
133
|
+
name="override", url="https://specs.apollo.dev/federation/v2.7"
|
129
134
|
)
|
130
135
|
|
131
136
|
|
@@ -147,7 +152,7 @@ class Override(FederationDirective):
|
|
147
152
|
)
|
148
153
|
class Inaccessible(FederationDirective):
|
149
154
|
imported_from: ClassVar[ImportedFrom] = ImportedFrom(
|
150
|
-
name="inaccessible", url="https://specs.apollo.dev/federation/v2.
|
155
|
+
name="inaccessible", url="https://specs.apollo.dev/federation/v2.7"
|
151
156
|
)
|
152
157
|
|
153
158
|
|
@@ -157,7 +162,7 @@ class Inaccessible(FederationDirective):
|
|
157
162
|
class ComposeDirective(FederationDirective):
|
158
163
|
name: str
|
159
164
|
imported_from: ClassVar[ImportedFrom] = ImportedFrom(
|
160
|
-
name="composeDirective", url="https://specs.apollo.dev/federation/v2.
|
165
|
+
name="composeDirective", url="https://specs.apollo.dev/federation/v2.7"
|
161
166
|
)
|
162
167
|
|
163
168
|
|
@@ -166,5 +171,58 @@ class ComposeDirective(FederationDirective):
|
|
166
171
|
)
|
167
172
|
class InterfaceObject(FederationDirective):
|
168
173
|
imported_from: ClassVar[ImportedFrom] = ImportedFrom(
|
169
|
-
name="interfaceObject", url="https://specs.apollo.dev/federation/v2.
|
174
|
+
name="interfaceObject", url="https://specs.apollo.dev/federation/v2.7"
|
175
|
+
)
|
176
|
+
|
177
|
+
|
178
|
+
@schema_directive(
|
179
|
+
locations=[
|
180
|
+
Location.FIELD_DEFINITION,
|
181
|
+
Location.OBJECT,
|
182
|
+
Location.INTERFACE,
|
183
|
+
Location.SCALAR,
|
184
|
+
Location.ENUM,
|
185
|
+
],
|
186
|
+
name="authenticated",
|
187
|
+
print_definition=False,
|
188
|
+
)
|
189
|
+
class Authenticated(FederationDirective):
|
190
|
+
imported_from: ClassVar[ImportedFrom] = ImportedFrom(
|
191
|
+
name="authenticated", url="https://specs.apollo.dev/federation/v2.7"
|
192
|
+
)
|
193
|
+
|
194
|
+
|
195
|
+
@schema_directive(
|
196
|
+
locations=[
|
197
|
+
Location.FIELD_DEFINITION,
|
198
|
+
Location.OBJECT,
|
199
|
+
Location.INTERFACE,
|
200
|
+
Location.SCALAR,
|
201
|
+
Location.ENUM,
|
202
|
+
],
|
203
|
+
name="requiresScopes",
|
204
|
+
print_definition=False,
|
205
|
+
)
|
206
|
+
class RequiresScopes(FederationDirective):
|
207
|
+
scopes: "List[List[str]]"
|
208
|
+
imported_from: ClassVar[ImportedFrom] = ImportedFrom(
|
209
|
+
name="requiresScopes", url="https://specs.apollo.dev/federation/v2.7"
|
210
|
+
)
|
211
|
+
|
212
|
+
|
213
|
+
@schema_directive(
|
214
|
+
locations=[
|
215
|
+
Location.FIELD_DEFINITION,
|
216
|
+
Location.OBJECT,
|
217
|
+
Location.INTERFACE,
|
218
|
+
Location.SCALAR,
|
219
|
+
Location.ENUM,
|
220
|
+
],
|
221
|
+
name="policy",
|
222
|
+
print_definition=False,
|
223
|
+
)
|
224
|
+
class Policy(FederationDirective):
|
225
|
+
policies: "List[List[str]]"
|
226
|
+
imported_from: ClassVar[ImportedFrom] = ImportedFrom(
|
227
|
+
name="policy", url="https://specs.apollo.dev/federation/v2.7"
|
170
228
|
)
|
@@ -2,9 +2,6 @@ from __future__ import annotations
|
|
2
2
|
|
3
3
|
import dataclasses
|
4
4
|
import keyword
|
5
|
-
from collections import defaultdict
|
6
|
-
from typing import TYPE_CHECKING, Tuple
|
7
|
-
from typing_extensions import Protocol
|
8
5
|
|
9
6
|
import libcst as cst
|
10
7
|
from graphql import (
|
@@ -22,7 +19,6 @@ from graphql import (
|
|
22
19
|
OperationType,
|
23
20
|
ScalarTypeDefinitionNode,
|
24
21
|
SchemaDefinitionNode,
|
25
|
-
SchemaExtensionNode,
|
26
22
|
StringValueNode,
|
27
23
|
TypeNode,
|
28
24
|
UnionTypeDefinitionNode,
|
@@ -31,14 +27,6 @@ from graphql import (
|
|
31
27
|
|
32
28
|
from strawberry.utils.str_converters import to_snake_case
|
33
29
|
|
34
|
-
if TYPE_CHECKING:
|
35
|
-
from graphql.language.ast import ConstDirectiveNode
|
36
|
-
|
37
|
-
|
38
|
-
class HasDirectives(Protocol):
|
39
|
-
directives: Tuple[ConstDirectiveNode]
|
40
|
-
|
41
|
-
|
42
30
|
_SCALAR_MAP = {
|
43
31
|
"Int": cst.Name("int"),
|
44
32
|
"Float": cst.Name("float"),
|
@@ -60,19 +48,6 @@ _SCALAR_MAP = {
|
|
60
48
|
}
|
61
49
|
|
62
50
|
|
63
|
-
def _is_federation_link_directive(directive: ConstDirectiveNode) -> bool:
|
64
|
-
if directive.name.value != "link":
|
65
|
-
return False
|
66
|
-
|
67
|
-
for argument in directive.arguments:
|
68
|
-
if argument.name.value == "url":
|
69
|
-
return argument.value.value.startswith(
|
70
|
-
"https://specs.apollo.dev/federation"
|
71
|
-
)
|
72
|
-
|
73
|
-
return False
|
74
|
-
|
75
|
-
|
76
51
|
def _get_field_type(
|
77
52
|
field_type: TypeNode, was_non_nullable: bool = False
|
78
53
|
) -> cst.BaseExpression:
|
@@ -110,10 +85,7 @@ def _get_field_type(
|
|
110
85
|
)
|
111
86
|
|
112
87
|
|
113
|
-
def
|
114
|
-
if isinstance(value, bool):
|
115
|
-
return cst.Name(value=str(value))
|
116
|
-
|
88
|
+
def _get_argument(name: str, value: str) -> cst.Arg:
|
117
89
|
if "\n" in value:
|
118
90
|
argument_value = cst.SimpleString(f'"""\n{value}\n"""')
|
119
91
|
elif '"' in value:
|
@@ -121,12 +93,6 @@ def _sanitize_argument(value: str | bool) -> cst.SimpleString | cst.Name:
|
|
121
93
|
else:
|
122
94
|
argument_value = cst.SimpleString(f'"{value}"')
|
123
95
|
|
124
|
-
return argument_value
|
125
|
-
|
126
|
-
|
127
|
-
def _get_argument(name: str, value: str | bool) -> cst.Arg:
|
128
|
-
argument_value = _sanitize_argument(value)
|
129
|
-
|
130
96
|
return cst.Arg(
|
131
97
|
value=argument_value,
|
132
98
|
keyword=cst.Name(name),
|
@@ -134,25 +100,7 @@ def _get_argument(name: str, value: str | bool) -> cst.Arg:
|
|
134
100
|
)
|
135
101
|
|
136
102
|
|
137
|
-
def
|
138
|
-
value = cst.List(
|
139
|
-
elements=[cst.Element(value=_sanitize_argument(value)) for value in values],
|
140
|
-
)
|
141
|
-
|
142
|
-
return cst.Arg(
|
143
|
-
value=value,
|
144
|
-
keyword=cst.Name(name),
|
145
|
-
equal=cst.AssignEqual(cst.SimpleWhitespace(""), cst.SimpleWhitespace("")),
|
146
|
-
)
|
147
|
-
|
148
|
-
|
149
|
-
def _get_field_value(
|
150
|
-
field: FieldDefinitionNode | InputValueDefinitionNode,
|
151
|
-
alias: str | None,
|
152
|
-
is_apollo_federation: bool,
|
153
|
-
) -> cst.Call | None:
|
154
|
-
description = field.description.value if field.description else None
|
155
|
-
|
103
|
+
def _get_field_value(description: str | None, alias: str | None) -> cst.Call | None:
|
156
104
|
args = list(
|
157
105
|
filter(
|
158
106
|
None,
|
@@ -163,24 +111,6 @@ def _get_field_value(
|
|
163
111
|
)
|
164
112
|
)
|
165
113
|
|
166
|
-
directives = _get_directives(field)
|
167
|
-
|
168
|
-
apollo_federation_args = _get_federation_arguments(directives)
|
169
|
-
|
170
|
-
if is_apollo_federation and apollo_federation_args:
|
171
|
-
args.extend(apollo_federation_args)
|
172
|
-
|
173
|
-
return cst.Call(
|
174
|
-
func=cst.Attribute(
|
175
|
-
value=cst.Attribute(
|
176
|
-
value=cst.Name("strawberry"),
|
177
|
-
attr=cst.Name("federation"),
|
178
|
-
),
|
179
|
-
attr=cst.Name("field"),
|
180
|
-
),
|
181
|
-
args=args,
|
182
|
-
)
|
183
|
-
|
184
114
|
if args:
|
185
115
|
return cst.Call(
|
186
116
|
func=cst.Attribute(
|
@@ -195,7 +125,6 @@ def _get_field_value(
|
|
195
125
|
|
196
126
|
def _get_field(
|
197
127
|
field: FieldDefinitionNode | InputValueDefinitionNode,
|
198
|
-
is_apollo_federation: bool,
|
199
128
|
) -> cst.SimpleStatementLine:
|
200
129
|
name = to_snake_case(field.name.value)
|
201
130
|
alias: str | None = None
|
@@ -212,67 +141,19 @@ def _get_field(
|
|
212
141
|
_get_field_type(field.type),
|
213
142
|
),
|
214
143
|
value=_get_field_value(
|
215
|
-
field
|
144
|
+
description=field.description.value if field.description else None,
|
145
|
+
alias=alias if alias != name else None,
|
216
146
|
),
|
217
147
|
)
|
218
148
|
]
|
219
149
|
)
|
220
150
|
|
221
151
|
|
222
|
-
def _get_directives(definition: HasDirectives) -> dict[str, list[dict[str, str]]]:
|
223
|
-
directives = defaultdict(list)
|
224
|
-
|
225
|
-
for directive in definition.directives:
|
226
|
-
directive_name = directive.name.value
|
227
|
-
|
228
|
-
directives[directive_name].append(
|
229
|
-
{
|
230
|
-
argument.name.value: argument.value.value
|
231
|
-
for argument in directive.arguments
|
232
|
-
}
|
233
|
-
)
|
234
|
-
|
235
|
-
return directives
|
236
|
-
|
237
|
-
|
238
|
-
def _get_federation_arguments(
|
239
|
-
directives: dict[str, list[dict[str, str]]],
|
240
|
-
) -> list[cst.Arg]:
|
241
|
-
def append_arg_from_directive(
|
242
|
-
directive: str, argument_name: str, keyword_name: str | None = None
|
243
|
-
):
|
244
|
-
keyword_name = keyword_name or directive
|
245
|
-
|
246
|
-
if directive in directives:
|
247
|
-
arguments.append(
|
248
|
-
_get_argument_list(
|
249
|
-
keyword_name,
|
250
|
-
[item[argument_name] for item in directives[directive]],
|
251
|
-
)
|
252
|
-
)
|
253
|
-
|
254
|
-
arguments: list[cst.Arg] = []
|
255
|
-
|
256
|
-
append_arg_from_directive("key", "fields", "keys")
|
257
|
-
append_arg_from_directive("requires", "fields")
|
258
|
-
append_arg_from_directive("provides", "fields")
|
259
|
-
append_arg_from_directive("tag", "name", "tags")
|
260
|
-
|
261
|
-
boolean_keys = ("shareable", "inaccessible", "external", "override")
|
262
|
-
|
263
|
-
arguments.extend(
|
264
|
-
_get_argument(key, True) for key in boolean_keys if directives.get(key, False)
|
265
|
-
)
|
266
|
-
|
267
|
-
return arguments
|
268
|
-
|
269
|
-
|
270
152
|
def _get_strawberry_decorator(
|
271
153
|
definition: ObjectTypeDefinitionNode
|
272
154
|
| ObjectTypeExtensionNode
|
273
155
|
| InterfaceTypeDefinitionNode
|
274
156
|
| InputObjectTypeDefinitionNode,
|
275
|
-
is_apollo_federation: bool,
|
276
157
|
) -> cst.Decorator:
|
277
158
|
type_ = {
|
278
159
|
ObjectTypeDefinitionNode: "type",
|
@@ -287,36 +168,15 @@ def _get_strawberry_decorator(
|
|
287
168
|
else None
|
288
169
|
)
|
289
170
|
|
290
|
-
directives = _get_directives(definition)
|
291
|
-
|
292
171
|
decorator: cst.BaseExpression = cst.Attribute(
|
293
172
|
value=cst.Name("strawberry"),
|
294
173
|
attr=cst.Name(type_),
|
295
174
|
)
|
296
175
|
|
297
|
-
arguments: list[cst.Arg] = []
|
298
|
-
|
299
176
|
if description is not None:
|
300
|
-
arguments.append(_get_argument("description", description.value))
|
301
|
-
|
302
|
-
federation_arguments = _get_federation_arguments(directives)
|
303
|
-
|
304
|
-
# and has any directive that is a federation directive
|
305
|
-
if is_apollo_federation and federation_arguments:
|
306
|
-
decorator = cst.Attribute(
|
307
|
-
value=cst.Attribute(
|
308
|
-
value=cst.Name("strawberry"),
|
309
|
-
attr=cst.Name("federation"),
|
310
|
-
),
|
311
|
-
attr=cst.Name(type_),
|
312
|
-
)
|
313
|
-
|
314
|
-
arguments.extend(federation_arguments)
|
315
|
-
|
316
|
-
if arguments:
|
317
177
|
decorator = cst.Call(
|
318
178
|
func=decorator,
|
319
|
-
args=
|
179
|
+
args=[_get_argument("description", description.value)],
|
320
180
|
)
|
321
181
|
|
322
182
|
return cst.Decorator(
|
@@ -329,9 +189,8 @@ def _get_class_definition(
|
|
329
189
|
| ObjectTypeExtensionNode
|
330
190
|
| InterfaceTypeDefinitionNode
|
331
191
|
| InputObjectTypeDefinitionNode,
|
332
|
-
is_apollo_federation: bool,
|
333
192
|
) -> cst.ClassDef:
|
334
|
-
decorator = _get_strawberry_decorator(definition
|
193
|
+
decorator = _get_strawberry_decorator(definition)
|
335
194
|
|
336
195
|
bases = (
|
337
196
|
[cst.Arg(cst.Name(interface.name.value)) for interface in definition.interfaces]
|
@@ -345,11 +204,7 @@ def _get_class_definition(
|
|
345
204
|
return cst.ClassDef(
|
346
205
|
name=cst.Name(definition.name.value),
|
347
206
|
bases=bases,
|
348
|
-
body=cst.IndentedBlock(
|
349
|
-
body=[
|
350
|
-
_get_field(field, is_apollo_federation) for field in definition.fields
|
351
|
-
]
|
352
|
-
),
|
207
|
+
body=cst.IndentedBlock(body=[_get_field(field) for field in definition.fields]),
|
353
208
|
decorators=[decorator],
|
354
209
|
)
|
355
210
|
|
@@ -388,7 +243,6 @@ def _get_schema_definition(
|
|
388
243
|
root_query_name: str | None,
|
389
244
|
root_mutation_name: str | None,
|
390
245
|
root_subscription_name: str | None,
|
391
|
-
is_apollo_federation: bool,
|
392
246
|
) -> cst.SimpleStatementLine | None:
|
393
247
|
if not any([root_query_name, root_mutation_name, root_subscription_name]):
|
394
248
|
return None
|
@@ -411,40 +265,17 @@ def _get_schema_definition(
|
|
411
265
|
if root_subscription_name:
|
412
266
|
args.append(_get_arg("subscription", root_subscription_name))
|
413
267
|
|
414
|
-
schema_call = cst.Call(
|
415
|
-
func=cst.Attribute(
|
416
|
-
value=cst.Name("strawberry"),
|
417
|
-
attr=cst.Name("Schema"),
|
418
|
-
),
|
419
|
-
args=args,
|
420
|
-
)
|
421
|
-
|
422
|
-
if is_apollo_federation:
|
423
|
-
args.append(
|
424
|
-
cst.Arg(
|
425
|
-
keyword=cst.Name("enable_federation_2"),
|
426
|
-
value=cst.Name("True"),
|
427
|
-
equal=cst.AssignEqual(
|
428
|
-
cst.SimpleWhitespace(""), cst.SimpleWhitespace("")
|
429
|
-
),
|
430
|
-
)
|
431
|
-
)
|
432
|
-
schema_call = cst.Call(
|
433
|
-
func=cst.Attribute(
|
434
|
-
value=cst.Attribute(
|
435
|
-
value=cst.Name(value="strawberry"),
|
436
|
-
attr=cst.Name(value="federation"),
|
437
|
-
),
|
438
|
-
attr=cst.Name(value="Schema"),
|
439
|
-
),
|
440
|
-
args=args,
|
441
|
-
)
|
442
|
-
|
443
268
|
return cst.SimpleStatementLine(
|
444
269
|
body=[
|
445
270
|
cst.Assign(
|
446
271
|
targets=[cst.AssignTarget(cst.Name("schema"))],
|
447
|
-
value=
|
272
|
+
value=cst.Call(
|
273
|
+
func=cst.Attribute(
|
274
|
+
value=cst.Name("strawberry"),
|
275
|
+
attr=cst.Name("Schema"),
|
276
|
+
),
|
277
|
+
args=args,
|
278
|
+
),
|
448
279
|
)
|
449
280
|
]
|
450
281
|
)
|
@@ -599,12 +430,6 @@ def codegen(schema: str) -> str:
|
|
599
430
|
|
600
431
|
object_types: dict[str, cst.ClassDef] = {}
|
601
432
|
|
602
|
-
# when we encounter a extend schema @link ..., we check if is an apollo federation schema
|
603
|
-
# and we use this variable to keep track of it, but at the moment the assumption is that
|
604
|
-
# the schema extension is always done at the top, this might not be the case all the
|
605
|
-
# time
|
606
|
-
is_apollo_federation = False
|
607
|
-
|
608
433
|
for definition in document.definitions:
|
609
434
|
if isinstance(
|
610
435
|
definition,
|
@@ -615,7 +440,7 @@ def codegen(schema: str) -> str:
|
|
615
440
|
ObjectTypeExtensionNode,
|
616
441
|
),
|
617
442
|
):
|
618
|
-
class_definition = _get_class_definition(definition
|
443
|
+
class_definition = _get_class_definition(definition)
|
619
444
|
|
620
445
|
object_types[definition.name.value] = class_definition
|
621
446
|
|
@@ -653,11 +478,6 @@ def codegen(schema: str) -> str:
|
|
653
478
|
definitions.append(cst.EmptyLine())
|
654
479
|
definitions.append(scalar_definition)
|
655
480
|
definitions.append(cst.EmptyLine())
|
656
|
-
elif isinstance(definition, SchemaExtensionNode):
|
657
|
-
is_apollo_federation = any(
|
658
|
-
_is_federation_link_directive(directive)
|
659
|
-
for directive in definition.directives
|
660
|
-
)
|
661
481
|
else:
|
662
482
|
raise NotImplementedError(f"Unknown definition {definition}")
|
663
483
|
|
@@ -676,7 +496,6 @@ def codegen(schema: str) -> str:
|
|
676
496
|
root_query_name=root_query_name,
|
677
497
|
root_mutation_name=root_mutation_name,
|
678
498
|
root_subscription_name=root_subscription_name,
|
679
|
-
is_apollo_federation=is_apollo_federation,
|
680
499
|
)
|
681
500
|
|
682
501
|
if schema_definition:
|
@@ -155,7 +155,7 @@ class ReservedType(NamedTuple):
|
|
155
155
|
# Handle annotated arguments such as Private[str] and DirectiveValue[str]
|
156
156
|
return type_has_annotation(other, self.type)
|
157
157
|
else:
|
158
|
-
# Handle both concrete and generic types (i.e Info, and Info
|
158
|
+
# Handle both concrete and generic types (i.e Info, and Info)
|
159
159
|
return (
|
160
160
|
issubclass(origin, self.type)
|
161
161
|
if isinstance(origin, type)
|
strawberry/types/info.py
CHANGED
@@ -10,10 +10,11 @@ from typing import (
|
|
10
10
|
Generic,
|
11
11
|
List,
|
12
12
|
Optional,
|
13
|
+
Tuple,
|
13
14
|
Type,
|
14
|
-
TypeVar,
|
15
15
|
Union,
|
16
16
|
)
|
17
|
+
from typing_extensions import TypeVar
|
17
18
|
|
18
19
|
from .nodes import convert_selections
|
19
20
|
|
@@ -29,8 +30,8 @@ if TYPE_CHECKING:
|
|
29
30
|
|
30
31
|
from .nodes import Selection
|
31
32
|
|
32
|
-
ContextType = TypeVar("ContextType")
|
33
|
-
RootValueType = TypeVar("RootValueType")
|
33
|
+
ContextType = TypeVar("ContextType", default=Any)
|
34
|
+
RootValueType = TypeVar("RootValueType", default=Any)
|
34
35
|
|
35
36
|
|
36
37
|
@dataclasses.dataclass
|
@@ -38,6 +39,21 @@ class Info(Generic[ContextType, RootValueType]):
|
|
38
39
|
_raw_info: GraphQLResolveInfo
|
39
40
|
_field: StrawberryField
|
40
41
|
|
42
|
+
def __class_getitem__(cls, types: Union[type, Tuple[type, ...]]) -> Type[Info]:
|
43
|
+
"""Workaround for when passing only one type.
|
44
|
+
|
45
|
+
Python doesn't yet support directly passing only one type to a generic class
|
46
|
+
that has typevars with defaults. This is a workaround for that.
|
47
|
+
|
48
|
+
See:
|
49
|
+
https://discuss.python.org/t/passing-only-one-typevar-of-two-when-using-defaults/49134
|
50
|
+
"""
|
51
|
+
|
52
|
+
if not isinstance(types, tuple):
|
53
|
+
types = (types, Any) # type: ignore
|
54
|
+
|
55
|
+
return super().__class_getitem__(types) # type: ignore
|
56
|
+
|
41
57
|
@property
|
42
58
|
def field_name(self) -> str:
|
43
59
|
return self._raw_info.field_name
|
{strawberry_graphql-0.221.0.dev1710955937.dist-info → strawberry_graphql-0.222.0.dist-info}/RECORD
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
strawberry/__init__.py,sha256=
|
1
|
+
strawberry/__init__.py,sha256=NP_R8Benm6W-v3Qqj3MSPm_CMickSCJIMaW2sZZ5oGs,1104
|
2
2
|
strawberry/__main__.py,sha256=3U77Eu21mJ-LY27RG-JEnpbh6Z63wGOom4i-EoLtUcY,59
|
3
3
|
strawberry/aiohttp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
strawberry/aiohttp/handlers/__init__.py,sha256=7EeGIIwrgJYHAS9XJnZLfRGL_GHrligKm39rrVt7qDA,241
|
@@ -127,19 +127,19 @@ strawberry/fastapi/handlers/graphql_ws_handler.py,sha256=U84lpd7Lxl2bEnFr9Qroswm
|
|
127
127
|
strawberry/fastapi/router.py,sha256=o55NLbL7n-LoKM30eUCJgzyPlRYPsybWb07L8-fcZZo,11573
|
128
128
|
strawberry/federation/__init__.py,sha256=FeUxLiBVuk9TKBmJJi51SeUaI8c80rS8hbl9No-hjII,535
|
129
129
|
strawberry/federation/argument.py,sha256=5qyJYlQGEZd6iXWseQ7dnnejCYj5HyglfK10jOCIJBg,802
|
130
|
-
strawberry/federation/enum.py,sha256=
|
131
|
-
strawberry/federation/field.py,sha256=
|
130
|
+
strawberry/federation/enum.py,sha256=wpM1z2NOkoBCqTVyD6vJJXoNlcnrNIERt2YpB4R9ybU,2977
|
131
|
+
strawberry/federation/field.py,sha256=HHOs8FL52_jxuYxPiR2EwJsXtk7LyapJeBUPqvJ6pCg,6184
|
132
132
|
strawberry/federation/mutation.py,sha256=0lV5HJwgw4HYR_59pwxWqnPs342HwakTNMc98w5Hb-c,43
|
133
|
-
strawberry/federation/object_type.py,sha256=
|
134
|
-
strawberry/federation/scalar.py,sha256=
|
133
|
+
strawberry/federation/object_type.py,sha256=nQLFbuS6KvAnGCGie_KXxjmtJC6gnQZFh5FAwFHTH-c,9037
|
134
|
+
strawberry/federation/scalar.py,sha256=jrSvaqfGEnj_Vl7b-LYMdq_NDMwfdu0t5Pfzlw5WAmU,3807
|
135
135
|
strawberry/federation/schema.py,sha256=Z9ZtDav5dwFQvts1XeeT4xoKeIhDwdGoocBUX-y233Y,13707
|
136
136
|
strawberry/federation/schema_directive.py,sha256=TpqoVeN3-iE-acndIRAVyU4LIXh6FTHz-Pv2kI8zGu0,1719
|
137
|
-
strawberry/federation/schema_directives.py,sha256=
|
137
|
+
strawberry/federation/schema_directives.py,sha256=gpJwpPg_UNiJdQtolY3qQ0lyVYD215c3JFyYH0yFRG8,6131
|
138
138
|
strawberry/federation/types.py,sha256=mM70g1aLgjplOc3SdtuJjy7NAKFLv35Z4BDC4s_j5us,301
|
139
139
|
strawberry/federation/union.py,sha256=QXeh-nhApqFtXa3To9MX_IwvtwErZBhWYnssUK7JB2E,1005
|
140
140
|
strawberry/field.py,sha256=2LvlnoQyRQHYcZV2Yy1E-2DYKXpOROUa8jyWgxG2QsI,18883
|
141
141
|
strawberry/field_extensions/__init__.py,sha256=0z6RG9jEO7jpAuyEaQhRI5A_30rdcvsBM0qMhLs8y2s,96
|
142
|
-
strawberry/field_extensions/input_mutation.py,sha256=
|
142
|
+
strawberry/field_extensions/input_mutation.py,sha256=a2zK97Fc5biqBt2ZlUPEPTQgMTRx6sJCSd3hSsjLSxI,2650
|
143
143
|
strawberry/file_uploads/__init__.py,sha256=v2-6FGBqnTnMPSUTFOiXpIutDMl-ga0PFtw5tKlcagk,50
|
144
144
|
strawberry/file_uploads/scalars.py,sha256=jccJh-h7t4naRiDzrszGoYsp95zdF30c7y5Ht0Zrk_s,131
|
145
145
|
strawberry/file_uploads/utils.py,sha256=U8gk1aHjWOBa_Opyvc47h6OpYToGq1QiSnEkI2kphdo,1112
|
@@ -194,7 +194,7 @@ strawberry/schema/types/__init__.py,sha256=oHO3COWhL3L1KLYCJNY1XFf5xt2GGtHiMC-Ua
|
|
194
194
|
strawberry/schema/types/base_scalars.py,sha256=Z_BmgwLicNexLipGyw6MmZ7OBnkGJU3ySgaY9SwBWrw,1837
|
195
195
|
strawberry/schema/types/concrete_type.py,sha256=HB30G1hMUuuvjAvfSe6ADS35iI_T_wKO-EprVOWTMSs,746
|
196
196
|
strawberry/schema/types/scalar.py,sha256=SVJ8HiKncCvOw2xwABI5xYaHcC7KkGHG-tx2WDtSoCA,2802
|
197
|
-
strawberry/schema_codegen/__init__.py,sha256=
|
197
|
+
strawberry/schema_codegen/__init__.py,sha256=U-ABa02BAfCN6zEGlc2LJEju18ErtGjbf0S8BhJXc6w,15592
|
198
198
|
strawberry/schema_directive.py,sha256=GxiOedFB-RJAflpQNUZv00C5Z6gavR-AYdsvoCA_0jc,1963
|
199
199
|
strawberry/starlite/__init__.py,sha256=v209swT8H9MljVL-npvANhEO1zz3__PSfxb_Ix-NoeE,134
|
200
200
|
strawberry/starlite/controller.py,sha256=x6Mm3r36cRfzo6hz9B4AYWbVh2QlYtndYcXFOr_3THM,11860
|
@@ -220,9 +220,9 @@ strawberry/type.py,sha256=KDztUFxVju4CEPPRzZYcyHtDNRrkFYxK-mI99GcqCgU,6511
|
|
220
220
|
strawberry/types/__init__.py,sha256=APb1Cjy6bxqFxIfDfempP6eb9NE3LYDwQ3gX7r07lXI,139
|
221
221
|
strawberry/types/execution.py,sha256=qCqDMJgdAFwdc3uPzVTAKsZlu6fgxPLrFwkoX_PFBq8,2775
|
222
222
|
strawberry/types/fields/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
223
|
-
strawberry/types/fields/resolver.py,sha256=
|
223
|
+
strawberry/types/fields/resolver.py,sha256=Lwy2XVKnTbDyibk9pPsWsunlm22akXjy-gKCg22Tp1A,14130
|
224
224
|
strawberry/types/graphql.py,sha256=3SWZEsa0Zy1eVW6vy75BnB7t9_lJVi6TBV3_1j3RNBs,687
|
225
|
-
strawberry/types/info.py,sha256=
|
225
|
+
strawberry/types/info.py,sha256=b1ZWW_wUop6XrGNcGHKBQeUYjlX-y8u3s2Wm_XhKPYI,3412
|
226
226
|
strawberry/types/nodes.py,sha256=2ZVa1HOFgHZ96QTfz3QEr1fufi6Sz9hAzcZxsN7KtGE,5026
|
227
227
|
strawberry/types/type_resolver.py,sha256=F0z_geS4VEun8EhD571LaTgI8ypjCeLfp910gF0Q3MY,6280
|
228
228
|
strawberry/types/types.py,sha256=t5MOV4xiutPL2Ka02u3Z2V3eqy2R2JPYQxsqCnY2Aqk,7139
|
@@ -241,8 +241,8 @@ strawberry/utils/logging.py,sha256=flS7hV0JiIOEdXcrIjda4WyIWix86cpHHFNJL8gl1y4,7
|
|
241
241
|
strawberry/utils/operation.py,sha256=Um-tBCPl3_bVFN2Ph7o1mnrxfxBes4HFCj6T0x4kZxE,1135
|
242
242
|
strawberry/utils/str_converters.py,sha256=avIgPVLg98vZH9mA2lhzVdyyjqzLsK2NdBw9mJQ02Xk,813
|
243
243
|
strawberry/utils/typing.py,sha256=Qxz1LwyVsNGV7LQW1dFsaUbsswj5LHBOdKLMom5eyEA,13491
|
244
|
-
strawberry_graphql-0.
|
245
|
-
strawberry_graphql-0.
|
246
|
-
strawberry_graphql-0.
|
247
|
-
strawberry_graphql-0.
|
248
|
-
strawberry_graphql-0.
|
244
|
+
strawberry_graphql-0.222.0.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
|
245
|
+
strawberry_graphql-0.222.0.dist-info/METADATA,sha256=yc6q0kAtPFBIqo0Whk1t6bxehAmcOKFfnd4-4lcAIcs,7740
|
246
|
+
strawberry_graphql-0.222.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
247
|
+
strawberry_graphql-0.222.0.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
|
248
|
+
strawberry_graphql-0.222.0.dist-info/RECORD,,
|
{strawberry_graphql-0.221.0.dev1710955937.dist-info → strawberry_graphql-0.222.0.dist-info}/LICENSE
RENAMED
File without changes
|
{strawberry_graphql-0.221.0.dev1710955937.dist-info → strawberry_graphql-0.222.0.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|