strawberry-graphql 0.235.1.dev1719337273__py3-none-any.whl → 0.236.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 +17 -11
- strawberry/aiohttp/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/aiohttp/handlers/graphql_ws_handler.py +3 -0
- strawberry/aiohttp/test/client.py +3 -0
- strawberry/aiohttp/views.py +3 -0
- strawberry/annotation.py +19 -22
- strawberry/asgi/__init__.py +3 -3
- strawberry/asgi/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/asgi/handlers/graphql_ws_handler.py +3 -0
- strawberry/asgi/test/client.py +3 -0
- strawberry/chalice/views.py +12 -3
- strawberry/channels/handlers/__init__.py +0 -0
- strawberry/channels/handlers/base.py +5 -5
- strawberry/channels/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/channels/handlers/graphql_ws_handler.py +3 -0
- strawberry/channels/handlers/http_handler.py +5 -2
- strawberry/channels/handlers/ws_handler.py +4 -1
- strawberry/channels/router.py +9 -5
- strawberry/channels/testing.py +11 -4
- strawberry/cli/commands/upgrade/__init__.py +13 -5
- strawberry/cli/commands/upgrade/_fake_progress.py +2 -1
- strawberry/cli/commands/upgrade/_run_codemod.py +18 -1
- strawberry/codegen/exceptions.py +8 -0
- strawberry/codegen/query_codegen.py +16 -7
- strawberry/codegen/types.py +32 -1
- strawberry/codemods/update_imports.py +136 -0
- strawberry/dataloader.py +13 -0
- strawberry/directive.py +52 -4
- strawberry/django/context.py +4 -1
- strawberry/django/test/client.py +3 -0
- strawberry/django/views.py +3 -0
- strawberry/exceptions/__init__.py +5 -5
- strawberry/exceptions/duplicated_type_name.py +1 -1
- strawberry/exceptions/invalid_argument_type.py +3 -3
- strawberry/exceptions/invalid_union_type.py +5 -6
- strawberry/exceptions/missing_arguments_annotations.py +1 -1
- strawberry/exceptions/missing_dependencies.py +10 -2
- strawberry/exceptions/missing_return_annotation.py +1 -1
- strawberry/exceptions/permission_fail_silently_requires_optional.py +3 -3
- strawberry/exceptions/scalar_already_registered.py +1 -1
- strawberry/exceptions/unresolved_field_type.py +2 -2
- strawberry/exceptions/utils/source_finder.py +5 -2
- strawberry/experimental/pydantic/conversion.py +5 -5
- strawberry/experimental/pydantic/conversion_types.py +4 -2
- strawberry/experimental/pydantic/error_type.py +2 -2
- strawberry/experimental/pydantic/fields.py +2 -2
- strawberry/experimental/pydantic/object_type.py +11 -7
- strawberry/experimental/pydantic/utils.py +4 -5
- strawberry/ext/dataclasses/dataclasses.py +2 -1
- strawberry/ext/mypy_plugin.py +10 -8
- strawberry/extensions/add_validation_rules.py +27 -23
- strawberry/extensions/base_extension.py +6 -4
- strawberry/extensions/directives.py +4 -1
- strawberry/extensions/disable_validation.py +15 -12
- strawberry/extensions/field_extension.py +11 -5
- strawberry/extensions/mask_errors.py +3 -0
- strawberry/extensions/max_aliases.py +21 -19
- strawberry/extensions/max_tokens.py +14 -16
- strawberry/extensions/parser_cache.py +22 -19
- strawberry/extensions/pyinstrument.py +4 -8
- strawberry/extensions/query_depth_limiter.py +22 -23
- strawberry/extensions/runner.py +3 -0
- strawberry/extensions/tracing/apollo.py +3 -0
- strawberry/extensions/tracing/datadog.py +7 -2
- strawberry/extensions/tracing/opentelemetry.py +3 -0
- strawberry/extensions/tracing/sentry.py +3 -0
- strawberry/extensions/tracing/utils.py +3 -0
- strawberry/extensions/utils.py +3 -0
- strawberry/extensions/validation_cache.py +23 -20
- strawberry/fastapi/context.py +3 -0
- strawberry/fastapi/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/fastapi/handlers/graphql_ws_handler.py +3 -0
- strawberry/fastapi/router.py +3 -0
- strawberry/federation/argument.py +4 -1
- strawberry/federation/enum.py +5 -3
- strawberry/federation/field.py +6 -3
- strawberry/federation/mutation.py +2 -0
- strawberry/federation/object_type.py +7 -4
- strawberry/federation/scalar.py +43 -20
- strawberry/federation/schema.py +12 -9
- strawberry/federation/schema_directive.py +2 -2
- strawberry/federation/schema_directives.py +19 -1
- strawberry/federation/types.py +5 -2
- strawberry/federation/union.py +27 -8
- strawberry/field_extensions/input_mutation.py +5 -2
- strawberry/file_uploads/scalars.py +3 -1
- strawberry/file_uploads/utils.py +3 -0
- strawberry/flask/views.py +8 -2
- strawberry/http/__init__.py +9 -0
- strawberry/http/async_base_view.py +4 -3
- strawberry/http/base.py +5 -7
- strawberry/http/exceptions.py +3 -0
- strawberry/http/ides.py +3 -0
- strawberry/http/sync_base_view.py +4 -3
- strawberry/http/temporal_response.py +3 -0
- strawberry/http/types.py +5 -2
- strawberry/http/typevars.py +3 -0
- strawberry/litestar/controller.py +6 -0
- strawberry/litestar/handlers/__init__.py +0 -0
- strawberry/litestar/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/litestar/handlers/graphql_ws_handler.py +3 -0
- strawberry/parent.py +27 -21
- strawberry/permission.py +70 -27
- strawberry/printer/ast_from_value.py +4 -1
- strawberry/printer/printer.py +8 -5
- strawberry/quart/views.py +3 -0
- strawberry/relay/exceptions.py +7 -0
- strawberry/relay/fields.py +70 -45
- strawberry/relay/types.py +78 -78
- strawberry/relay/utils.py +10 -1
- strawberry/resolvers.py +3 -0
- strawberry/sanic/context.py +3 -0
- strawberry/sanic/utils.py +10 -8
- strawberry/sanic/views.py +5 -9
- strawberry/scalars.py +6 -2
- strawberry/schema/base.py +7 -4
- strawberry/schema/compat.py +12 -2
- strawberry/schema/config.py +3 -0
- strawberry/schema/exceptions.py +3 -0
- strawberry/schema/execute.py +3 -0
- strawberry/schema/name_converter.py +12 -9
- strawberry/schema/schema.py +46 -9
- strawberry/schema/schema_converter.py +16 -14
- strawberry/schema/types/base_scalars.py +3 -1
- strawberry/schema/types/concrete_type.py +4 -4
- strawberry/schema/types/scalar.py +8 -1
- strawberry/schema/validation_rules/one_of.py +3 -0
- strawberry/schema_codegen/__init__.py +3 -0
- strawberry/schema_directive.py +2 -2
- strawberry/starlite/controller.py +3 -0
- strawberry/starlite/handlers/__init__.py +0 -0
- strawberry/starlite/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/starlite/handlers/graphql_ws_handler.py +3 -0
- strawberry/subscriptions/__init__.py +6 -0
- strawberry/subscriptions/protocols/graphql_transport_ws/__init__.py +5 -0
- strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py +12 -17
- strawberry/subscriptions/protocols/graphql_transport_ws/types.py +21 -25
- strawberry/subscriptions/protocols/graphql_ws/__init__.py +14 -0
- strawberry/subscriptions/protocols/graphql_ws/handlers.py +8 -5
- strawberry/subscriptions/protocols/graphql_ws/types.py +11 -0
- strawberry/test/client.py +44 -29
- strawberry/tools/create_type.py +27 -8
- strawberry/tools/merge_types.py +5 -3
- strawberry/types/__init__.py +8 -1
- strawberry/{arguments.py → types/arguments.py} +44 -13
- strawberry/{auto.py → types/auto.py} +21 -3
- strawberry/types/{types.py → base.py} +234 -10
- strawberry/{enum.py → types/enum.py} +69 -9
- strawberry/types/execution.py +3 -0
- strawberry/{field.py → types/field.py} +46 -23
- strawberry/types/fields/resolver.py +2 -2
- strawberry/types/graphql.py +3 -0
- strawberry/types/info.py +50 -7
- strawberry/{lazy_type.py → types/lazy_type.py} +50 -0
- strawberry/types/mutation.py +351 -0
- strawberry/types/nodes.py +4 -2
- strawberry/{object_type.py → types/object_type.py} +108 -29
- strawberry/{private.py → types/private.py} +13 -6
- strawberry/{custom_scalar.py → types/scalar.py} +39 -23
- strawberry/types/type_resolver.py +21 -16
- strawberry/{union.py → types/union.py} +24 -9
- strawberry/{unset.py → types/unset.py} +20 -0
- strawberry/utils/aio.py +8 -0
- strawberry/utils/await_maybe.py +3 -0
- strawberry/utils/dataclasses.py +3 -0
- strawberry/utils/debug.py +5 -2
- strawberry/utils/deprecations.py +3 -0
- strawberry/utils/graphql_lexer.py +3 -0
- strawberry/utils/importer.py +3 -0
- strawberry/utils/inspect.py +39 -30
- strawberry/utils/logging.py +3 -0
- strawberry/utils/operation.py +3 -0
- strawberry/utils/str_converters.py +3 -0
- strawberry/utils/typing.py +33 -16
- {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/METADATA +1 -1
- strawberry_graphql-0.236.0.dist-info/RECORD +255 -0
- strawberry/mutation.py +0 -8
- strawberry/type.py +0 -232
- strawberry_graphql-0.235.1.dev1719337273.dist-info/RECORD +0 -252
- {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/LICENSE +0 -0
- {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/WHEEL +0 -0
- {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/entry_points.txt +0 -0
strawberry/__init__.py
CHANGED
@@ -1,22 +1,28 @@
|
|
1
|
+
"""Strawberry is a Python library for GraphQL.
|
2
|
+
|
3
|
+
Strawberry is a Python library for GraphQL that aims to stay close to the GraphQL
|
4
|
+
specification and allow for a more natural way of defining GraphQL schemas.
|
5
|
+
"""
|
6
|
+
|
1
7
|
from . import experimental, federation, relay
|
2
|
-
from .arguments import argument
|
3
|
-
from .auto import auto
|
4
|
-
from .custom_scalar import scalar
|
5
8
|
from .directive import directive, directive_field
|
6
|
-
from .enum import enum, enum_value
|
7
|
-
from .field import field
|
8
|
-
from .lazy_type import LazyType, lazy
|
9
|
-
from .mutation import mutation, subscription
|
10
|
-
from .object_type import asdict, input, interface, type
|
11
9
|
from .parent import Parent
|
12
10
|
from .permission import BasePermission
|
13
|
-
from .private import Private
|
14
11
|
from .scalars import ID
|
15
12
|
from .schema import Schema
|
16
13
|
from .schema_directive import schema_directive
|
14
|
+
from .types.arguments import argument
|
15
|
+
from .types.auto import auto
|
16
|
+
from .types.enum import enum, enum_value
|
17
|
+
from .types.field import field
|
17
18
|
from .types.info import Info
|
18
|
-
from .
|
19
|
-
from .
|
19
|
+
from .types.lazy_type import LazyType, lazy
|
20
|
+
from .types.mutation import mutation, subscription
|
21
|
+
from .types.object_type import asdict, input, interface, type
|
22
|
+
from .types.private import Private
|
23
|
+
from .types.scalar import scalar
|
24
|
+
from .types.union import union
|
25
|
+
from .types.unset import UNSET
|
20
26
|
|
21
27
|
__all__ = [
|
22
28
|
"BasePermission",
|
strawberry/aiohttp/views.py
CHANGED
strawberry/annotation.py
CHANGED
@@ -20,26 +20,26 @@ from typing import (
|
|
20
20
|
)
|
21
21
|
from typing_extensions import Annotated, Self, get_args, get_origin
|
22
22
|
|
23
|
-
from strawberry.custom_scalar import ScalarDefinition
|
24
|
-
from strawberry.enum import EnumDefinition
|
25
23
|
from strawberry.exceptions.not_a_strawberry_enum import NotAStrawberryEnumError
|
26
|
-
from strawberry.
|
27
|
-
from strawberry.private import is_private
|
28
|
-
from strawberry.type import (
|
24
|
+
from strawberry.types.base import (
|
29
25
|
StrawberryList,
|
26
|
+
StrawberryObjectDefinition,
|
30
27
|
StrawberryOptional,
|
31
28
|
StrawberryTypeVar,
|
32
29
|
get_object_definition,
|
33
30
|
has_object_definition,
|
34
31
|
)
|
35
|
-
from strawberry.types.
|
36
|
-
from strawberry.
|
32
|
+
from strawberry.types.enum import EnumDefinition
|
33
|
+
from strawberry.types.lazy_type import LazyType
|
34
|
+
from strawberry.types.private import is_private
|
35
|
+
from strawberry.types.scalar import ScalarDefinition
|
36
|
+
from strawberry.types.unset import UNSET
|
37
37
|
from strawberry.utils.typing import eval_type, is_generic, is_type_var
|
38
38
|
|
39
39
|
if TYPE_CHECKING:
|
40
|
-
from strawberry.
|
41
|
-
from strawberry.
|
42
|
-
from strawberry.union import StrawberryUnion
|
40
|
+
from strawberry.types.base import StrawberryType
|
41
|
+
from strawberry.types.field import StrawberryField
|
42
|
+
from strawberry.types.union import StrawberryUnion
|
43
43
|
|
44
44
|
|
45
45
|
ASYNC_TYPES = (
|
@@ -135,9 +135,6 @@ class StrawberryAnnotation:
|
|
135
135
|
return self.__resolve_cache__
|
136
136
|
|
137
137
|
def _resolve(self) -> Union[StrawberryType, type]:
|
138
|
-
# TODO: I wonder if this resolve should be creating types?
|
139
|
-
# types should only be created once, in the schema converter maybe?
|
140
|
-
# but maybe the cache above is fine
|
141
138
|
evaled_type = cast(Any, self.evaluate())
|
142
139
|
|
143
140
|
if is_private(evaled_type):
|
@@ -229,7 +226,7 @@ class StrawberryAnnotation:
|
|
229
226
|
|
230
227
|
def create_union(self, evaled_type: Type[Any], args: list[Any]) -> StrawberryUnion:
|
231
228
|
# Prevent import cycles
|
232
|
-
from strawberry.union import StrawberryUnion
|
229
|
+
from strawberry.types.union import StrawberryUnion
|
233
230
|
|
234
231
|
# TODO: Deal with Forward References/origin
|
235
232
|
if isinstance(evaled_type, StrawberryUnion):
|
@@ -293,8 +290,7 @@ class StrawberryAnnotation:
|
|
293
290
|
|
294
291
|
@classmethod
|
295
292
|
def _is_optional(cls, annotation: Any, args: List[Any]) -> bool:
|
296
|
-
"""Returns True if the annotation is Optional[SomeType]"""
|
297
|
-
|
293
|
+
"""Returns True if the annotation is Optional[SomeType]."""
|
298
294
|
# Optionals are represented as unions
|
299
295
|
if not cls._is_union(annotation, args):
|
300
296
|
return False
|
@@ -306,8 +302,7 @@ class StrawberryAnnotation:
|
|
306
302
|
|
307
303
|
@classmethod
|
308
304
|
def _is_list(cls, annotation: Any) -> bool:
|
309
|
-
"""Returns True if annotation is a List"""
|
310
|
-
|
305
|
+
"""Returns True if annotation is a List."""
|
311
306
|
annotation_origin = get_origin(annotation)
|
312
307
|
annotation_mro = getattr(annotation, "__mro__", [])
|
313
308
|
is_list = any(x is list for x in annotation_mro)
|
@@ -321,7 +316,7 @@ class StrawberryAnnotation:
|
|
321
316
|
@classmethod
|
322
317
|
def _is_strawberry_type(cls, evaled_type: Any) -> bool:
|
323
318
|
# Prevent import cycles
|
324
|
-
from strawberry.union import StrawberryUnion
|
319
|
+
from strawberry.types.union import StrawberryUnion
|
325
320
|
|
326
321
|
if isinstance(evaled_type, EnumDefinition):
|
327
322
|
return True
|
@@ -347,8 +342,7 @@ class StrawberryAnnotation:
|
|
347
342
|
|
348
343
|
@classmethod
|
349
344
|
def _is_union(cls, annotation: Any, args: List[Any]) -> bool:
|
350
|
-
"""Returns True if annotation is a Union"""
|
351
|
-
|
345
|
+
"""Returns True if annotation is a Union."""
|
352
346
|
# this check is needed because unions declared with the new syntax `A | B`
|
353
347
|
# don't have a `__origin__` property on them, but they are instances of
|
354
348
|
# `UnionType`, which is only available in Python 3.10+
|
@@ -366,7 +360,7 @@ class StrawberryAnnotation:
|
|
366
360
|
if annotation_origin is typing.Union:
|
367
361
|
return True
|
368
362
|
|
369
|
-
from strawberry.union import StrawberryUnion
|
363
|
+
from strawberry.types.union import StrawberryUnion
|
370
364
|
|
371
365
|
return any(isinstance(arg, StrawberryUnion) for arg in args)
|
372
366
|
|
@@ -389,3 +383,6 @@ def _is_input_type(type_: Any) -> bool:
|
|
389
383
|
return False
|
390
384
|
|
391
385
|
return type_.__strawberry_definition__.is_input
|
386
|
+
|
387
|
+
|
388
|
+
__all__ = ["StrawberryAnnotation"]
|
strawberry/asgi/__init__.py
CHANGED
@@ -117,12 +117,12 @@ class GraphQL(
|
|
117
117
|
else:
|
118
118
|
self.graphql_ide = graphql_ide
|
119
119
|
|
120
|
-
async def __call__(self, scope:
|
120
|
+
async def __call__(self, scope: Request, receive: Receive, send: Send) -> None:
|
121
121
|
if scope["type"] == "http":
|
122
|
-
return await self.handle_http(scope, receive, send)
|
122
|
+
return await self.handle_http(scope, receive, send) # type: ignore
|
123
123
|
|
124
124
|
elif scope["type"] == "websocket":
|
125
|
-
ws = WebSocket(scope
|
125
|
+
ws = WebSocket(scope, receive=receive, send=send) # type: ignore
|
126
126
|
preferred_protocol = self.pick_preferred_protocol(ws)
|
127
127
|
|
128
128
|
if preferred_protocol == GRAPHQL_TRANSPORT_WS_PROTOCOL:
|
strawberry/asgi/test/client.py
CHANGED
strawberry/chalice/views.py
CHANGED
@@ -94,10 +94,16 @@ class GraphQLView(
|
|
94
94
|
http_status_code: int,
|
95
95
|
headers: Optional[Dict[str, str | List[str]]] = None,
|
96
96
|
) -> Response:
|
97
|
-
"""
|
98
|
-
|
97
|
+
"""A wrapper for error responses.
|
98
|
+
|
99
|
+
Args:
|
100
|
+
message: The error message.
|
101
|
+
error_code: The error code.
|
102
|
+
http_status_code: The HTTP status code.
|
103
|
+
headers: The headers to include in the response.
|
104
|
+
|
99
105
|
Returns:
|
100
|
-
|
106
|
+
An errors response.
|
101
107
|
"""
|
102
108
|
body = {"Code": error_code, "Message": message}
|
103
109
|
|
@@ -139,3 +145,6 @@ class GraphQLView(
|
|
139
145
|
message=e.reason,
|
140
146
|
http_status_code=e.status_code,
|
141
147
|
)
|
148
|
+
|
149
|
+
|
150
|
+
__all__ = ["GraphQLView"]
|
File without changes
|
@@ -92,7 +92,7 @@ class ChannelsConsumer(AsyncConsumer):
|
|
92
92
|
Utility to listen for channels messages for this consumer inside
|
93
93
|
a resolver (usually inside a subscription).
|
94
94
|
|
95
|
-
|
95
|
+
Args:
|
96
96
|
type:
|
97
97
|
The type of the message to wait for.
|
98
98
|
timeout:
|
@@ -104,7 +104,6 @@ class ChannelsConsumer(AsyncConsumer):
|
|
104
104
|
execution and then discarded using `self.channel_layer.group_discard`
|
105
105
|
at the end of the execution.
|
106
106
|
"""
|
107
|
-
|
108
107
|
warnings.warn("Use listen_to_channel instead", DeprecationWarning, stacklevel=2)
|
109
108
|
if self.channel_layer is None:
|
110
109
|
raise RuntimeError(
|
@@ -152,7 +151,7 @@ class ChannelsConsumer(AsyncConsumer):
|
|
152
151
|
Utility to listen for channels messages for this consumer inside
|
153
152
|
a resolver (usually inside a subscription).
|
154
153
|
|
155
|
-
|
154
|
+
Args:
|
156
155
|
type:
|
157
156
|
The type of the message to wait for.
|
158
157
|
timeout:
|
@@ -164,7 +163,6 @@ class ChannelsConsumer(AsyncConsumer):
|
|
164
163
|
execution and then discarded using `self.channel_layer.group_discard`
|
165
164
|
at the end of the execution.
|
166
165
|
"""
|
167
|
-
|
168
166
|
# Code to acquire resource (Channels subscriptions)
|
169
167
|
if self.channel_layer is None:
|
170
168
|
raise RuntimeError(
|
@@ -201,7 +199,6 @@ class ChannelsConsumer(AsyncConsumer):
|
|
201
199
|
Seperated to allow user code to be run after subscribing to channels
|
202
200
|
and before blocking to wait for incoming channel messages.
|
203
201
|
"""
|
204
|
-
|
205
202
|
while True:
|
206
203
|
awaitable = queue.get()
|
207
204
|
if timeout is not None:
|
@@ -215,3 +212,6 @@ class ChannelsConsumer(AsyncConsumer):
|
|
215
212
|
|
216
213
|
class ChannelsWSConsumer(ChannelsConsumer, AsyncJsonWebsocketConsumer):
|
217
214
|
"""Base channels websocket async consumer."""
|
215
|
+
|
216
|
+
|
217
|
+
__all__ = ["ChannelsConsumer", "ChannelsWSConsumer"]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
"""GraphQLHTTPHandler
|
1
|
+
"""GraphQLHTTPHandler.
|
2
2
|
|
3
3
|
A consumer to provide a graphql endpoint, and optionally graphiql.
|
4
4
|
"""
|
@@ -25,7 +25,7 @@ from strawberry.http.sync_base_view import SyncBaseHTTPView, SyncHTTPRequestAdap
|
|
25
25
|
from strawberry.http.temporal_response import TemporalResponse
|
26
26
|
from strawberry.http.types import FormData
|
27
27
|
from strawberry.http.typevars import Context, RootValue
|
28
|
-
from strawberry.unset import UNSET
|
28
|
+
from strawberry.types.unset import UNSET
|
29
29
|
|
30
30
|
from .base import ChannelsConsumer
|
31
31
|
|
@@ -304,3 +304,6 @@ class SyncGraphQLHTTPConsumer(
|
|
304
304
|
root_value: Optional[RootValue] = UNSET,
|
305
305
|
) -> ChannelsResponse:
|
306
306
|
return super().run(request, context, root_value)
|
307
|
+
|
308
|
+
|
309
|
+
__all__ = ["GraphQLHTTPConsumer", "SyncGraphQLHTTPConsumer"]
|
@@ -15,7 +15,7 @@ if TYPE_CHECKING:
|
|
15
15
|
|
16
16
|
|
17
17
|
class GraphQLWSConsumer(ChannelsWSConsumer):
|
18
|
-
"""A channels websocket consumer for GraphQL
|
18
|
+
"""A channels websocket consumer for GraphQL.
|
19
19
|
|
20
20
|
This handles the connections, then hands off to the appropriate
|
21
21
|
handler based on the subprotocol.
|
@@ -126,3 +126,6 @@ class GraphQLWSConsumer(ChannelsWSConsumer):
|
|
126
126
|
"connection_params": connection_params,
|
127
127
|
"ws": request,
|
128
128
|
} # type: ignore
|
129
|
+
|
130
|
+
|
131
|
+
__all__ = ["GraphQLWSConsumer"]
|
strawberry/channels/router.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""GraphQLWebSocketRouter
|
1
|
+
"""GraphQLWebSocketRouter.
|
2
2
|
|
3
3
|
This is a simple router class that might be better placed as part of Channels itself.
|
4
4
|
It's a simple "SubProtocolRouter" that selects the websocket subprotocol based
|
@@ -21,11 +21,12 @@ if TYPE_CHECKING:
|
|
21
21
|
|
22
22
|
|
23
23
|
class GraphQLProtocolTypeRouter(ProtocolTypeRouter):
|
24
|
-
"""
|
25
|
-
Convenience class to set up GraphQL on both HTTP and Websocket, optionally with a
|
26
|
-
Django application for all other HTTP routes:
|
24
|
+
"""HTTP and Websocket GraphQL type router.
|
27
25
|
|
28
|
-
|
26
|
+
Convenience class to set up GraphQL on both HTTP and Websocket,
|
27
|
+
optionally with a Django application for all other HTTP routes.
|
28
|
+
|
29
|
+
```python
|
29
30
|
from strawberry.channels import GraphQLProtocolTypeRouter
|
30
31
|
from django.core.asgi import get_asgi_application
|
31
32
|
|
@@ -63,3 +64,6 @@ class GraphQLProtocolTypeRouter(ProtocolTypeRouter):
|
|
63
64
|
),
|
64
65
|
}
|
65
66
|
)
|
67
|
+
|
68
|
+
|
69
|
+
__all__ = ["GraphQLProtocolTypeRouter"]
|
strawberry/channels/testing.py
CHANGED
@@ -41,8 +41,8 @@ if TYPE_CHECKING:
|
|
41
41
|
|
42
42
|
|
43
43
|
class GraphQLWebsocketCommunicator(WebsocketCommunicator):
|
44
|
-
"""
|
45
|
-
|
44
|
+
"""A test communicator for GraphQL over Websockets.
|
45
|
+
|
46
46
|
```python
|
47
47
|
import pytest
|
48
48
|
from strawberry.channels.testing import GraphQLWebsocketCommunicator
|
@@ -72,12 +72,16 @@ class GraphQLWebsocketCommunicator(WebsocketCommunicator):
|
|
72
72
|
connection_params: dict = {},
|
73
73
|
**kwargs: Any,
|
74
74
|
) -> None:
|
75
|
-
"""
|
75
|
+
"""Create a new communicator.
|
76
76
|
|
77
77
|
Args:
|
78
78
|
application: Your asgi application that encapsulates the strawberry schema.
|
79
79
|
path: the url endpoint for the schema.
|
80
80
|
protocol: currently this supports `graphql-transport-ws` only.
|
81
|
+
connection_params: a dictionary of connection parameters to send to the server.
|
82
|
+
headers: a list of tuples to be sent as headers to the server.
|
83
|
+
subprotocols: an ordered list of preferred subprotocols to be sent to the server.
|
84
|
+
**kwargs: additional arguments to be passed to the `WebsocketCommunicator` constructor.
|
81
85
|
"""
|
82
86
|
self.protocol = protocol
|
83
87
|
subprotocols = kwargs.get("subprotocols", [])
|
@@ -155,7 +159,7 @@ class GraphQLWebsocketCommunicator(WebsocketCommunicator):
|
|
155
159
|
return
|
156
160
|
|
157
161
|
def process_errors(self, errors: List[GraphQLFormattedError]) -> List[GraphQLError]:
|
158
|
-
"""
|
162
|
+
"""Reconstructs a GraphQLError from a FormattedGraphQLError."""
|
159
163
|
result = []
|
160
164
|
for f_error in errors:
|
161
165
|
error = GraphQLError(
|
@@ -165,3 +169,6 @@ class GraphQLWebsocketCommunicator(WebsocketCommunicator):
|
|
165
169
|
error.path = f_error.get("path", None)
|
166
170
|
result.append(error)
|
167
171
|
return result
|
172
|
+
|
173
|
+
|
174
|
+
__all__ = ["GraphQLWebsocketCommunicator"]
|
@@ -11,11 +11,13 @@ from libcst.codemod import CodemodContext
|
|
11
11
|
|
12
12
|
from strawberry.cli.app import app
|
13
13
|
from strawberry.codemods.annotated_unions import ConvertUnionToAnnotatedUnion
|
14
|
+
from strawberry.codemods.update_imports import UpdateImportsCodemod
|
14
15
|
|
15
16
|
from ._run_codemod import run_codemod
|
16
17
|
|
17
18
|
codemods = {
|
18
19
|
"annotated-union": ConvertUnionToAnnotatedUnion,
|
20
|
+
"update-imports": UpdateImportsCodemod,
|
19
21
|
}
|
20
22
|
|
21
23
|
|
@@ -46,11 +48,17 @@ def upgrade(
|
|
46
48
|
|
47
49
|
python_target_version = tuple(int(x) for x in python_target.split("."))
|
48
50
|
|
49
|
-
transformer
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
transformer: ConvertUnionToAnnotatedUnion | UpdateImportsCodemod
|
52
|
+
|
53
|
+
if codemod == "update-imports":
|
54
|
+
transformer = UpdateImportsCodemod(context=CodemodContext())
|
55
|
+
|
56
|
+
else:
|
57
|
+
transformer = ConvertUnionToAnnotatedUnion(
|
58
|
+
CodemodContext(),
|
59
|
+
use_pipe_syntax=python_target_version >= (3, 10),
|
60
|
+
use_typing_extensions=use_typing_extensions,
|
61
|
+
)
|
54
62
|
|
55
63
|
files: list[str] = []
|
56
64
|
|
@@ -6,7 +6,8 @@ from rich.progress import TaskID
|
|
6
6
|
class FakeProgress:
|
7
7
|
"""A fake progress bar that does nothing.
|
8
8
|
|
9
|
-
This is used when the user has only one file to process.
|
9
|
+
This is used when the user has only one file to process.
|
10
|
+
"""
|
10
11
|
|
11
12
|
def advance(self, task_id: TaskID) -> None:
|
12
13
|
pass
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
2
2
|
|
3
3
|
import contextlib
|
4
4
|
import os
|
5
|
+
from importlib.metadata import version
|
5
6
|
from multiprocessing import Pool, cpu_count
|
6
7
|
from typing import TYPE_CHECKING, Any, Dict, Generator, Sequence, Type, Union
|
7
8
|
|
@@ -18,13 +19,29 @@ ProgressType = Union[Type[Progress], Type[FakeProgress]]
|
|
18
19
|
PoolType = Union[Type[Pool], Type[DummyPool]] # type: ignore
|
19
20
|
|
20
21
|
|
22
|
+
def _get_libcst_version() -> tuple[int, int, int]:
|
23
|
+
package_version_str = version("libcst")
|
24
|
+
|
25
|
+
try:
|
26
|
+
major, minor, patch = map(int, package_version_str.split("."))
|
27
|
+
except ValueError:
|
28
|
+
major, minor, patch = (0, 0, 0)
|
29
|
+
|
30
|
+
return major, minor, patch
|
31
|
+
|
32
|
+
|
21
33
|
def _execute_transform_wrap(
|
22
34
|
job: Dict[str, Any],
|
23
35
|
) -> ExecutionResult:
|
36
|
+
additional_kwargs: Dict[str, Any] = {}
|
37
|
+
|
38
|
+
if _get_libcst_version() >= (1, 4, 0):
|
39
|
+
additional_kwargs["scratch"] = {}
|
40
|
+
|
24
41
|
# TODO: maybe capture warnings?
|
25
42
|
with open(os.devnull, "w") as null: # noqa: PTH123
|
26
43
|
with contextlib.redirect_stderr(null):
|
27
|
-
return _execute_transform(**job)
|
44
|
+
return _execute_transform(**job, **additional_kwargs)
|
28
45
|
|
29
46
|
|
30
47
|
def _get_progress_and_pool(
|
strawberry/codegen/exceptions.py
CHANGED
@@ -12,3 +12,11 @@ class NoOperationNameProvidedError(CodegenError):
|
|
12
12
|
|
13
13
|
class MultipleOperationsProvidedError(CodegenError):
|
14
14
|
pass
|
15
|
+
|
16
|
+
|
17
|
+
__all__ = [
|
18
|
+
"CodegenError",
|
19
|
+
"NoOperationProvidedError",
|
20
|
+
"NoOperationNameProvidedError",
|
21
|
+
"MultipleOperationsProvidedError",
|
22
|
+
]
|
@@ -42,19 +42,19 @@ from graphql import (
|
|
42
42
|
parse,
|
43
43
|
)
|
44
44
|
|
45
|
-
from strawberry.
|
46
|
-
from strawberry.enum import EnumDefinition
|
47
|
-
from strawberry.lazy_type import LazyType
|
48
|
-
from strawberry.type import (
|
45
|
+
from strawberry.types.base import (
|
49
46
|
StrawberryList,
|
47
|
+
StrawberryObjectDefinition,
|
50
48
|
StrawberryOptional,
|
51
49
|
StrawberryType,
|
52
50
|
get_object_definition,
|
53
51
|
has_object_definition,
|
54
52
|
)
|
55
|
-
from strawberry.types.
|
56
|
-
from strawberry.
|
57
|
-
from strawberry.
|
53
|
+
from strawberry.types.enum import EnumDefinition
|
54
|
+
from strawberry.types.lazy_type import LazyType
|
55
|
+
from strawberry.types.scalar import ScalarDefinition, ScalarWrapper
|
56
|
+
from strawberry.types.union import StrawberryUnion
|
57
|
+
from strawberry.types.unset import UNSET
|
58
58
|
from strawberry.utils.str_converters import capitalize_first, to_camel_case
|
59
59
|
|
60
60
|
from .exceptions import (
|
@@ -917,3 +917,12 @@ class QueryCodegen:
|
|
917
917
|
)
|
918
918
|
self._collect_type(graphql_enum)
|
919
919
|
return graphql_enum
|
920
|
+
|
921
|
+
|
922
|
+
__all__ = [
|
923
|
+
"QueryCodegen",
|
924
|
+
"QueryCodegenPlugin",
|
925
|
+
"ConsolePlugin",
|
926
|
+
"CodegenFile",
|
927
|
+
"CodegenResult",
|
928
|
+
]
|
strawberry/codegen/types.py
CHANGED
@@ -7,7 +7,7 @@ if TYPE_CHECKING:
|
|
7
7
|
from enum import EnumMeta
|
8
8
|
from typing_extensions import Literal
|
9
9
|
|
10
|
-
from strawberry.unset import UnsetType
|
10
|
+
from strawberry.types.unset import UnsetType
|
11
11
|
|
12
12
|
|
13
13
|
@dataclass
|
@@ -194,3 +194,34 @@ class GraphQLOperation:
|
|
194
194
|
variables: List[GraphQLVariable]
|
195
195
|
type: GraphQLObjectType
|
196
196
|
variables_type: Optional[GraphQLObjectType]
|
197
|
+
|
198
|
+
|
199
|
+
__all__ = [
|
200
|
+
"GraphQLOptional",
|
201
|
+
"GraphQLList",
|
202
|
+
"GraphQLUnion",
|
203
|
+
"GraphQLField",
|
204
|
+
"GraphQLFragmentSpread",
|
205
|
+
"GraphQLObjectType",
|
206
|
+
"GraphQLFragmentType",
|
207
|
+
"GraphQLEnum",
|
208
|
+
"GraphQLScalar",
|
209
|
+
"GraphQLType",
|
210
|
+
"GraphQLFieldSelection",
|
211
|
+
"GraphQLInlineFragment",
|
212
|
+
"GraphQLSelection",
|
213
|
+
"GraphQLStringValue",
|
214
|
+
"GraphQLIntValue",
|
215
|
+
"GraphQLFloatValue",
|
216
|
+
"GraphQLEnumValue",
|
217
|
+
"GraphQLBoolValue",
|
218
|
+
"GraphQLNullValue",
|
219
|
+
"GraphQLListValue",
|
220
|
+
"GraphQLObjectValue",
|
221
|
+
"GraphQLVariableReference",
|
222
|
+
"GraphQLArgumentValue",
|
223
|
+
"GraphQLArgument",
|
224
|
+
"GraphQLDirective",
|
225
|
+
"GraphQLVariable",
|
226
|
+
"GraphQLOperation",
|
227
|
+
]
|