strawberry-graphql 0.255.0__py3-none-any.whl → 0.256.1__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 +9 -9
- strawberry/aiohttp/test/client.py +10 -8
- strawberry/aiohttp/views.py +5 -7
- strawberry/annotation.py +12 -15
- strawberry/asgi/__init__.py +3 -6
- strawberry/asgi/test/client.py +9 -8
- strawberry/chalice/views.py +4 -2
- strawberry/channels/__init__.py +1 -1
- strawberry/channels/handlers/base.py +3 -7
- strawberry/channels/handlers/http_handler.py +5 -6
- strawberry/channels/handlers/ws_handler.py +3 -4
- strawberry/channels/testing.py +5 -9
- strawberry/cli/commands/codegen.py +9 -9
- strawberry/cli/commands/upgrade/__init__.py +2 -3
- strawberry/cli/commands/upgrade/_run_codemod.py +7 -5
- strawberry/codegen/exceptions.py +2 -2
- strawberry/codegen/plugins/print_operation.py +6 -6
- strawberry/codegen/plugins/python.py +6 -6
- strawberry/codegen/plugins/typescript.py +3 -3
- strawberry/codegen/query_codegen.py +29 -34
- strawberry/codegen/types.py +35 -34
- strawberry/codemods/annotated_unions.py +5 -2
- strawberry/dataloader.py +13 -20
- strawberry/directive.py +12 -5
- strawberry/django/test/client.py +4 -4
- strawberry/django/views.py +4 -5
- strawberry/exceptions/__init__.py +24 -24
- strawberry/exceptions/conflicting_arguments.py +2 -2
- strawberry/exceptions/duplicated_type_name.py +3 -3
- strawberry/exceptions/handler.py +7 -7
- strawberry/exceptions/invalid_union_type.py +2 -2
- strawberry/exceptions/missing_arguments_annotations.py +2 -2
- strawberry/exceptions/missing_field_annotation.py +2 -2
- strawberry/exceptions/object_is_not_an_enum.py +2 -2
- strawberry/exceptions/private_strawberry_field.py +2 -2
- strawberry/exceptions/syntax.py +4 -4
- strawberry/exceptions/utils/source_finder.py +7 -6
- strawberry/experimental/pydantic/__init__.py +3 -3
- strawberry/experimental/pydantic/_compat.py +14 -14
- strawberry/experimental/pydantic/conversion.py +2 -2
- strawberry/experimental/pydantic/conversion_types.py +3 -3
- strawberry/experimental/pydantic/error_type.py +18 -16
- strawberry/experimental/pydantic/exceptions.py +5 -5
- strawberry/experimental/pydantic/fields.py +2 -13
- strawberry/experimental/pydantic/object_type.py +20 -22
- strawberry/experimental/pydantic/utils.py +6 -10
- strawberry/ext/dataclasses/dataclasses.py +3 -3
- strawberry/ext/mypy_plugin.py +6 -9
- strawberry/extensions/__init__.py +7 -8
- strawberry/extensions/add_validation_rules.py +5 -3
- strawberry/extensions/base_extension.py +4 -4
- strawberry/extensions/context.py +15 -14
- strawberry/extensions/directives.py +2 -2
- strawberry/extensions/disable_validation.py +1 -1
- strawberry/extensions/field_extension.py +2 -1
- strawberry/extensions/mask_errors.py +3 -2
- strawberry/extensions/max_aliases.py +2 -2
- strawberry/extensions/max_tokens.py +1 -1
- strawberry/extensions/parser_cache.py +2 -1
- strawberry/extensions/pyinstrument.py +5 -2
- strawberry/extensions/query_depth_limiter.py +13 -13
- strawberry/extensions/runner.py +7 -7
- strawberry/extensions/tracing/apollo.py +11 -9
- strawberry/extensions/tracing/datadog.py +3 -1
- strawberry/extensions/tracing/opentelemetry.py +7 -10
- strawberry/extensions/utils.py +3 -3
- strawberry/extensions/validation_cache.py +2 -1
- strawberry/fastapi/context.py +3 -3
- strawberry/fastapi/router.py +9 -14
- strawberry/federation/__init__.py +4 -4
- strawberry/federation/argument.py +2 -1
- strawberry/federation/enum.py +8 -8
- strawberry/federation/field.py +25 -28
- strawberry/federation/object_type.py +24 -26
- strawberry/federation/scalar.py +7 -8
- strawberry/federation/schema.py +30 -36
- strawberry/federation/schema_directive.py +5 -5
- strawberry/federation/schema_directives.py +14 -14
- strawberry/federation/union.py +3 -2
- strawberry/field_extensions/input_mutation.py +1 -2
- strawberry/file_uploads/utils.py +4 -3
- strawberry/flask/views.py +3 -2
- strawberry/http/__init__.py +6 -6
- strawberry/http/async_base_view.py +9 -14
- strawberry/http/base.py +5 -4
- strawberry/http/ides.py +1 -1
- strawberry/http/parse_content_type.py +1 -2
- strawberry/http/sync_base_view.py +3 -5
- strawberry/http/temporal_response.py +1 -2
- strawberry/http/types.py +3 -2
- strawberry/litestar/controller.py +8 -14
- strawberry/parent.py +1 -2
- strawberry/permission.py +6 -8
- strawberry/printer/ast_from_value.py +2 -1
- strawberry/printer/printer.py +50 -30
- strawberry/quart/views.py +3 -3
- strawberry/relay/exceptions.py +4 -4
- strawberry/relay/fields.py +22 -24
- strawberry/relay/types.py +29 -27
- strawberry/relay/utils.py +4 -4
- strawberry/sanic/utils.py +4 -4
- strawberry/sanic/views.py +5 -7
- strawberry/scalars.py +2 -2
- strawberry/schema/base.py +16 -11
- strawberry/schema/compat.py +4 -4
- strawberry/schema/execute.py +6 -10
- strawberry/schema/name_converter.py +3 -3
- strawberry/schema/schema.py +37 -25
- strawberry/schema/schema_converter.py +22 -24
- strawberry/schema/subscribe.py +4 -3
- strawberry/schema/types/base_scalars.py +1 -1
- strawberry/schema/types/concrete_type.py +2 -2
- strawberry/schema/types/scalar.py +3 -4
- strawberry/schema_codegen/__init__.py +4 -4
- strawberry/schema_directive.py +8 -8
- strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py +8 -9
- strawberry/subscriptions/protocols/graphql_transport_ws/types.py +16 -16
- strawberry/subscriptions/protocols/graphql_ws/handlers.py +6 -5
- strawberry/subscriptions/protocols/graphql_ws/types.py +13 -13
- strawberry/test/__init__.py +1 -1
- strawberry/test/client.py +21 -19
- strawberry/tools/create_type.py +4 -3
- strawberry/tools/merge_types.py +1 -2
- strawberry/types/__init__.py +1 -1
- strawberry/types/arguments.py +10 -12
- strawberry/types/auto.py +2 -2
- strawberry/types/base.py +17 -21
- strawberry/types/enum.py +3 -5
- strawberry/types/execution.py +8 -12
- strawberry/types/field.py +26 -31
- strawberry/types/fields/resolver.py +15 -17
- strawberry/types/graphql.py +2 -2
- strawberry/types/info.py +5 -9
- strawberry/types/lazy_type.py +3 -5
- strawberry/types/mutation.py +25 -28
- strawberry/types/nodes.py +11 -9
- strawberry/types/object_type.py +14 -16
- strawberry/types/private.py +1 -2
- strawberry/types/scalar.py +2 -2
- strawberry/types/type_resolver.py +5 -5
- strawberry/types/union.py +8 -11
- strawberry/types/unset.py +3 -3
- strawberry/utils/aio.py +3 -8
- strawberry/utils/await_maybe.py +3 -2
- strawberry/utils/debug.py +2 -2
- strawberry/utils/deprecations.py +2 -2
- strawberry/utils/inspect.py +3 -5
- strawberry/utils/str_converters.py +1 -1
- strawberry/utils/typing.py +38 -67
- {strawberry_graphql-0.255.0.dist-info → strawberry_graphql-0.256.1.dist-info}/METADATA +3 -6
- strawberry_graphql-0.256.1.dist-info/RECORD +236 -0
- strawberry_graphql-0.255.0.dist-info/RECORD +0 -236
- {strawberry_graphql-0.255.0.dist-info → strawberry_graphql-0.256.1.dist-info}/LICENSE +0 -0
- {strawberry_graphql-0.255.0.dist-info → strawberry_graphql-0.256.1.dist-info}/WHEEL +0 -0
- {strawberry_graphql-0.255.0.dist-info → strawberry_graphql-0.256.1.dist-info}/entry_points.txt +0 -0
strawberry/tools/create_type.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import types
|
2
|
-
from
|
2
|
+
from collections.abc import Sequence
|
3
|
+
from typing import Optional
|
3
4
|
|
4
5
|
import strawberry
|
5
6
|
from strawberry.types.field import StrawberryField
|
@@ -7,13 +8,13 @@ from strawberry.types.field import StrawberryField
|
|
7
8
|
|
8
9
|
def create_type(
|
9
10
|
name: str,
|
10
|
-
fields:
|
11
|
+
fields: list[StrawberryField],
|
11
12
|
is_input: bool = False,
|
12
13
|
is_interface: bool = False,
|
13
14
|
description: Optional[str] = None,
|
14
15
|
directives: Optional[Sequence[object]] = (),
|
15
16
|
extend: bool = False,
|
16
|
-
) ->
|
17
|
+
) -> type:
|
17
18
|
"""Create a Strawberry type from a list of StrawberryFields.
|
18
19
|
|
19
20
|
Args:
|
strawberry/tools/merge_types.py
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
import warnings
|
2
2
|
from collections import Counter
|
3
3
|
from itertools import chain
|
4
|
-
from typing import Tuple
|
5
4
|
|
6
5
|
import strawberry
|
7
6
|
from strawberry.types.base import has_object_definition
|
8
7
|
|
9
8
|
|
10
|
-
def merge_types(name: str, types:
|
9
|
+
def merge_types(name: str, types: tuple[type, ...]) -> type:
|
11
10
|
"""Merge multiple Strawberry types into one.
|
12
11
|
|
13
12
|
For example, given two queries `A` and `B`, one can merge them into a
|
strawberry/types/__init__.py
CHANGED
strawberry/types/arguments.py
CHANGED
@@ -2,18 +2,16 @@ from __future__ import annotations
|
|
2
2
|
|
3
3
|
import inspect
|
4
4
|
import warnings
|
5
|
+
from collections.abc import Iterable, Mapping
|
5
6
|
from typing import (
|
6
7
|
TYPE_CHECKING,
|
8
|
+
Annotated,
|
7
9
|
Any,
|
8
|
-
Dict,
|
9
|
-
Iterable,
|
10
|
-
List,
|
11
|
-
Mapping,
|
12
10
|
Optional,
|
13
11
|
Union,
|
14
12
|
cast,
|
15
13
|
)
|
16
|
-
from typing_extensions import
|
14
|
+
from typing_extensions import get_args, get_origin
|
17
15
|
|
18
16
|
from strawberry.annotation import StrawberryAnnotation
|
19
17
|
from strawberry.exceptions import MultipleStrawberryArgumentsError, UnsupportedTypeError
|
@@ -34,7 +32,7 @@ if TYPE_CHECKING:
|
|
34
32
|
from strawberry.types.scalar import ScalarDefinition, ScalarWrapper
|
35
33
|
|
36
34
|
|
37
|
-
DEPRECATED_NAMES:
|
35
|
+
DEPRECATED_NAMES: dict[str, str] = {
|
38
36
|
"UNSET": (
|
39
37
|
"importing `UNSET` from `strawberry.arguments` is deprecated, "
|
40
38
|
"import instead from `strawberry` or from `strawberry.types.unset`"
|
@@ -140,7 +138,7 @@ class StrawberryArgument:
|
|
140
138
|
def convert_argument(
|
141
139
|
value: object,
|
142
140
|
type_: Union[StrawberryType, type],
|
143
|
-
scalar_registry:
|
141
|
+
scalar_registry: dict[object, Union[ScalarWrapper, ScalarDefinition]],
|
144
142
|
config: StrawberryConfig,
|
145
143
|
) -> object:
|
146
144
|
# TODO: move this somewhere else and make it first class
|
@@ -197,11 +195,11 @@ def convert_argument(
|
|
197
195
|
|
198
196
|
|
199
197
|
def convert_arguments(
|
200
|
-
value:
|
201
|
-
arguments:
|
202
|
-
scalar_registry:
|
198
|
+
value: dict[str, Any],
|
199
|
+
arguments: list[StrawberryArgument],
|
200
|
+
scalar_registry: dict[object, Union[ScalarWrapper, ScalarDefinition]],
|
203
201
|
config: StrawberryConfig,
|
204
|
-
) ->
|
202
|
+
) -> dict[str, Any]:
|
205
203
|
"""Converts a nested dictionary to a dictionary of actual types.
|
206
204
|
|
207
205
|
It deals with conversion of input types to proper dataclasses and
|
@@ -283,9 +281,9 @@ def __getattr__(name: str) -> Any:
|
|
283
281
|
|
284
282
|
# TODO: check exports
|
285
283
|
__all__ = [ # noqa: F822
|
284
|
+
"UNSET", # for backwards compatibility # type: ignore
|
286
285
|
"StrawberryArgument",
|
287
286
|
"StrawberryArgumentAnnotation",
|
288
|
-
"UNSET", # for backwards compatibility # type: ignore
|
289
287
|
"argument",
|
290
288
|
"is_unset", # for backwards compatibility # type: ignore
|
291
289
|
]
|
strawberry/types/auto.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from typing import Any, Optional, Union, cast
|
4
|
-
from typing_extensions import
|
3
|
+
from typing import Annotated, Any, Optional, Union, cast
|
4
|
+
from typing_extensions import get_args, get_origin
|
5
5
|
|
6
6
|
from strawberry.annotation import StrawberryAnnotation
|
7
7
|
from strawberry.types.base import StrawberryType
|
strawberry/types/base.py
CHANGED
@@ -7,12 +7,7 @@ from typing import (
|
|
7
7
|
Any,
|
8
8
|
Callable,
|
9
9
|
ClassVar,
|
10
|
-
Dict,
|
11
|
-
List,
|
12
|
-
Mapping,
|
13
10
|
Optional,
|
14
|
-
Sequence,
|
15
|
-
Type,
|
16
11
|
TypeVar,
|
17
12
|
Union,
|
18
13
|
overload,
|
@@ -25,6 +20,7 @@ from strawberry.utils.typing import is_concrete_generic
|
|
25
20
|
from strawberry.utils.typing import is_generic as is_type_generic
|
26
21
|
|
27
22
|
if TYPE_CHECKING:
|
23
|
+
from collections.abc import Mapping, Sequence
|
28
24
|
from typing_extensions import TypeGuard
|
29
25
|
|
30
26
|
from graphql import GraphQLAbstractType, GraphQLResolveInfo
|
@@ -44,7 +40,7 @@ class StrawberryType(ABC):
|
|
44
40
|
"""
|
45
41
|
|
46
42
|
@property
|
47
|
-
def type_params(self) ->
|
43
|
+
def type_params(self) -> list[TypeVar]:
|
48
44
|
return []
|
49
45
|
|
50
46
|
@property
|
@@ -55,9 +51,9 @@ class StrawberryType(ABC):
|
|
55
51
|
def copy_with(
|
56
52
|
self,
|
57
53
|
type_var_map: Mapping[
|
58
|
-
str, Union[StrawberryType,
|
54
|
+
str, Union[StrawberryType, type[WithStrawberryObjectDefinition]]
|
59
55
|
],
|
60
|
-
) -> Union[StrawberryType,
|
56
|
+
) -> Union[StrawberryType, type[WithStrawberryObjectDefinition]]:
|
61
57
|
raise NotImplementedError()
|
62
58
|
|
63
59
|
@property
|
@@ -93,7 +89,7 @@ class StrawberryType(ABC):
|
|
93
89
|
|
94
90
|
class StrawberryContainer(StrawberryType):
|
95
91
|
def __init__(
|
96
|
-
self, of_type: Union[StrawberryType,
|
92
|
+
self, of_type: Union[StrawberryType, type[WithStrawberryObjectDefinition], type]
|
97
93
|
) -> None:
|
98
94
|
self.of_type = of_type
|
99
95
|
|
@@ -110,7 +106,7 @@ class StrawberryContainer(StrawberryType):
|
|
110
106
|
return super().__eq__(other)
|
111
107
|
|
112
108
|
@property
|
113
|
-
def type_params(self) ->
|
109
|
+
def type_params(self) -> list[TypeVar]:
|
114
110
|
if has_object_definition(self.of_type):
|
115
111
|
parameters = getattr(self.of_type, "__parameters__", None)
|
116
112
|
|
@@ -125,7 +121,7 @@ class StrawberryContainer(StrawberryType):
|
|
125
121
|
def copy_with(
|
126
122
|
self,
|
127
123
|
type_var_map: Mapping[
|
128
|
-
str, Union[StrawberryType,
|
124
|
+
str, Union[StrawberryType, type[WithStrawberryObjectDefinition]]
|
129
125
|
],
|
130
126
|
) -> Self:
|
131
127
|
of_type_copy = self.of_type
|
@@ -180,7 +176,7 @@ class StrawberryTypeVar(StrawberryType):
|
|
180
176
|
return self.type_var == type_var
|
181
177
|
|
182
178
|
@property
|
183
|
-
def type_params(self) ->
|
179
|
+
def type_params(self) -> list[TypeVar]:
|
184
180
|
return [self.type_var]
|
185
181
|
|
186
182
|
def __eq__(self, other: object) -> bool:
|
@@ -201,7 +197,7 @@ class WithStrawberryObjectDefinition(Protocol):
|
|
201
197
|
|
202
198
|
def has_object_definition(
|
203
199
|
obj: Any,
|
204
|
-
) -> TypeGuard[
|
200
|
+
) -> TypeGuard[type[WithStrawberryObjectDefinition]]:
|
205
201
|
if hasattr(obj, "__strawberry_definition__"):
|
206
202
|
return True
|
207
203
|
# TODO: Generics remove dunder members here, so we inject it here.
|
@@ -254,9 +250,9 @@ class StrawberryObjectDefinition(StrawberryType):
|
|
254
250
|
name: str
|
255
251
|
is_input: bool
|
256
252
|
is_interface: bool
|
257
|
-
origin:
|
253
|
+
origin: type[Any]
|
258
254
|
description: Optional[str]
|
259
|
-
interfaces:
|
255
|
+
interfaces: list[StrawberryObjectDefinition]
|
260
256
|
extend: bool
|
261
257
|
directives: Optional[Sequence[object]]
|
262
258
|
is_type_of: Optional[Callable[[Any, GraphQLResolveInfo], bool]]
|
@@ -264,7 +260,7 @@ class StrawberryObjectDefinition(StrawberryType):
|
|
264
260
|
Callable[[Any, GraphQLResolveInfo, GraphQLAbstractType], str]
|
265
261
|
]
|
266
262
|
|
267
|
-
fields:
|
263
|
+
fields: list[StrawberryField]
|
268
264
|
|
269
265
|
concrete_of: Optional[StrawberryObjectDefinition] = None
|
270
266
|
"""Concrete implementations of Generic TypeDefinitions fill this in"""
|
@@ -296,7 +292,7 @@ class StrawberryObjectDefinition(StrawberryType):
|
|
296
292
|
|
297
293
|
def copy_with(
|
298
294
|
self, type_var_map: Mapping[str, Union[StrawberryType, type]]
|
299
|
-
) ->
|
295
|
+
) -> type[WithStrawberryObjectDefinition]:
|
300
296
|
fields = [field.copy_with(type_var_map) for field in self.fields]
|
301
297
|
|
302
298
|
new_type_definition = StrawberryObjectDefinition(
|
@@ -353,7 +349,7 @@ class StrawberryObjectDefinition(StrawberryType):
|
|
353
349
|
)
|
354
350
|
|
355
351
|
@property
|
356
|
-
def specialized_type_var_map(self) -> Optional[
|
352
|
+
def specialized_type_var_map(self) -> Optional[dict[str, type]]:
|
357
353
|
return get_specialized_type_var_map(self.origin)
|
358
354
|
|
359
355
|
@property
|
@@ -361,14 +357,14 @@ class StrawberryObjectDefinition(StrawberryType):
|
|
361
357
|
return not self.is_input and not self.is_interface
|
362
358
|
|
363
359
|
@property
|
364
|
-
def type_params(self) ->
|
365
|
-
type_params:
|
360
|
+
def type_params(self) -> list[TypeVar]:
|
361
|
+
type_params: list[TypeVar] = []
|
366
362
|
for field in self.fields:
|
367
363
|
type_params.extend(field.type_params)
|
368
364
|
|
369
365
|
return type_params
|
370
366
|
|
371
|
-
def is_implemented_by(self, root:
|
367
|
+
def is_implemented_by(self, root: type[WithStrawberryObjectDefinition]) -> bool:
|
372
368
|
# TODO: Support dicts
|
373
369
|
if isinstance(root, dict):
|
374
370
|
raise NotImplementedError
|
strawberry/types/enum.py
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
import dataclasses
|
2
|
+
from collections.abc import Iterable, Mapping
|
2
3
|
from enum import EnumMeta
|
3
4
|
from typing import (
|
4
5
|
Any,
|
5
6
|
Callable,
|
6
|
-
Iterable,
|
7
|
-
List,
|
8
|
-
Mapping,
|
9
7
|
Optional,
|
10
8
|
TypeVar,
|
11
9
|
Union,
|
@@ -29,7 +27,7 @@ class EnumValue:
|
|
29
27
|
class EnumDefinition(StrawberryType):
|
30
28
|
wrapped_cls: EnumMeta
|
31
29
|
name: str
|
32
|
-
values:
|
30
|
+
values: list[EnumValue]
|
33
31
|
description: Optional[str]
|
34
32
|
directives: Iterable[object] = ()
|
35
33
|
|
@@ -228,4 +226,4 @@ def enum(
|
|
228
226
|
return wrap(cls)
|
229
227
|
|
230
228
|
|
231
|
-
__all__ = ["
|
229
|
+
__all__ = ["EnumDefinition", "EnumValue", "EnumValueDefinition", "enum", "enum_value"]
|
strawberry/types/execution.py
CHANGED
@@ -4,12 +4,7 @@ import dataclasses
|
|
4
4
|
from typing import (
|
5
5
|
TYPE_CHECKING,
|
6
6
|
Any,
|
7
|
-
Dict,
|
8
|
-
Iterable,
|
9
|
-
List,
|
10
7
|
Optional,
|
11
|
-
Tuple,
|
12
|
-
Type,
|
13
8
|
runtime_checkable,
|
14
9
|
)
|
15
10
|
from typing_extensions import Protocol, TypedDict
|
@@ -19,6 +14,7 @@ from graphql import specified_rules
|
|
19
14
|
from strawberry.utils.operation import get_first_operation, get_operation_type
|
20
15
|
|
21
16
|
if TYPE_CHECKING:
|
17
|
+
from collections.abc import Iterable
|
22
18
|
from typing_extensions import NotRequired
|
23
19
|
|
24
20
|
from graphql import ASTValidationRule
|
@@ -37,12 +33,12 @@ class ExecutionContext:
|
|
37
33
|
schema: Schema
|
38
34
|
allowed_operations: Iterable[OperationType]
|
39
35
|
context: Any = None
|
40
|
-
variables: Optional[
|
36
|
+
variables: Optional[dict[str, Any]] = None
|
41
37
|
parse_options: ParseOptions = dataclasses.field(
|
42
38
|
default_factory=lambda: ParseOptions()
|
43
39
|
)
|
44
40
|
root_value: Optional[Any] = None
|
45
|
-
validation_rules:
|
41
|
+
validation_rules: tuple[type[ASTValidationRule], ...] = dataclasses.field(
|
46
42
|
default_factory=lambda: tuple(specified_rules)
|
47
43
|
)
|
48
44
|
|
@@ -52,9 +48,9 @@ class ExecutionContext:
|
|
52
48
|
# Values that get populated during the GraphQL execution so that they can be
|
53
49
|
# accessed by extensions
|
54
50
|
graphql_document: Optional[DocumentNode] = None
|
55
|
-
errors: Optional[
|
51
|
+
errors: Optional[list[GraphQLError]] = None
|
56
52
|
result: Optional[GraphQLExecutionResult] = None
|
57
|
-
extensions_results:
|
53
|
+
extensions_results: dict[str, Any] = dataclasses.field(default_factory=dict)
|
58
54
|
|
59
55
|
def __post_init__(self, provided_operation_name: str | None) -> None:
|
60
56
|
self._provided_operation_name = provided_operation_name
|
@@ -91,9 +87,9 @@ class ExecutionContext:
|
|
91
87
|
|
92
88
|
@dataclasses.dataclass
|
93
89
|
class ExecutionResult:
|
94
|
-
data: Optional[
|
95
|
-
errors: Optional[
|
96
|
-
extensions: Optional[
|
90
|
+
data: Optional[dict[str, Any]]
|
91
|
+
errors: Optional[list[GraphQLError]]
|
92
|
+
extensions: Optional[dict[str, Any]] = None
|
97
93
|
|
98
94
|
|
99
95
|
@dataclasses.dataclass
|
strawberry/types/field.py
CHANGED
@@ -4,18 +4,13 @@ import contextlib
|
|
4
4
|
import copy
|
5
5
|
import dataclasses
|
6
6
|
import sys
|
7
|
+
from collections.abc import Awaitable, Coroutine, Mapping, Sequence
|
7
8
|
from functools import cached_property
|
8
9
|
from typing import (
|
9
10
|
TYPE_CHECKING,
|
10
11
|
Any,
|
11
|
-
Awaitable,
|
12
12
|
Callable,
|
13
|
-
Coroutine,
|
14
|
-
List,
|
15
|
-
Mapping,
|
16
13
|
Optional,
|
17
|
-
Sequence,
|
18
|
-
Type,
|
19
14
|
TypeVar,
|
20
15
|
Union,
|
21
16
|
cast,
|
@@ -83,17 +78,17 @@ class StrawberryField(dataclasses.Field):
|
|
83
78
|
python_name: Optional[str] = None,
|
84
79
|
graphql_name: Optional[str] = None,
|
85
80
|
type_annotation: Optional[StrawberryAnnotation] = None,
|
86
|
-
origin: Optional[Union[
|
81
|
+
origin: Optional[Union[type, Callable, staticmethod, classmethod]] = None,
|
87
82
|
is_subscription: bool = False,
|
88
83
|
description: Optional[str] = None,
|
89
84
|
base_resolver: Optional[StrawberryResolver] = None,
|
90
|
-
permission_classes:
|
85
|
+
permission_classes: list[type[BasePermission]] = (), # type: ignore
|
91
86
|
default: object = dataclasses.MISSING,
|
92
87
|
default_factory: Union[Callable[[], Any], object] = dataclasses.MISSING,
|
93
88
|
metadata: Optional[Mapping[Any, Any]] = None,
|
94
89
|
deprecation_reason: Optional[str] = None,
|
95
90
|
directives: Sequence[object] = (),
|
96
|
-
extensions:
|
91
|
+
extensions: list[FieldExtension] = (), # type: ignore
|
97
92
|
) -> None:
|
98
93
|
# basic fields are fields with no provided resolver
|
99
94
|
is_basic_field = not base_resolver
|
@@ -124,7 +119,7 @@ class StrawberryField(dataclasses.Field):
|
|
124
119
|
self.description: Optional[str] = description
|
125
120
|
self.origin = origin
|
126
121
|
|
127
|
-
self._arguments: Optional[
|
122
|
+
self._arguments: Optional[list[StrawberryArgument]] = None
|
128
123
|
self._base_resolver: Optional[StrawberryResolver] = None
|
129
124
|
if base_resolver is not None:
|
130
125
|
self.base_resolver = base_resolver
|
@@ -142,9 +137,9 @@ class StrawberryField(dataclasses.Field):
|
|
142
137
|
|
143
138
|
self.is_subscription = is_subscription
|
144
139
|
|
145
|
-
self.permission_classes:
|
140
|
+
self.permission_classes: list[type[BasePermission]] = list(permission_classes)
|
146
141
|
self.directives = list(directives)
|
147
|
-
self.extensions:
|
142
|
+
self.extensions: list[FieldExtension] = list(extensions)
|
148
143
|
|
149
144
|
# Automatically add the permissions extension
|
150
145
|
if len(self.permission_classes):
|
@@ -213,7 +208,7 @@ class StrawberryField(dataclasses.Field):
|
|
213
208
|
return self
|
214
209
|
|
215
210
|
def get_result(
|
216
|
-
self, source: Any, info: Optional[Info], args:
|
211
|
+
self, source: Any, info: Optional[Info], args: list[Any], kwargs: Any
|
217
212
|
) -> Union[Awaitable[Any], Any]:
|
218
213
|
"""Calls the resolver defined for the StrawberryField.
|
219
214
|
|
@@ -238,14 +233,14 @@ class StrawberryField(dataclasses.Field):
|
|
238
233
|
return not self.base_resolver and not self.extensions
|
239
234
|
|
240
235
|
@property
|
241
|
-
def arguments(self) ->
|
236
|
+
def arguments(self) -> list[StrawberryArgument]:
|
242
237
|
if self._arguments is None:
|
243
238
|
self._arguments = self.base_resolver.arguments if self.base_resolver else []
|
244
239
|
|
245
240
|
return self._arguments
|
246
241
|
|
247
242
|
@arguments.setter
|
248
|
-
def arguments(self, value:
|
243
|
+
def arguments(self, value: list[StrawberryArgument]) -> None:
|
249
244
|
self._arguments = value
|
250
245
|
|
251
246
|
@property
|
@@ -299,7 +294,7 @@ class StrawberryField(dataclasses.Field):
|
|
299
294
|
self,
|
300
295
|
) -> Union[ # type: ignore [valid-type]
|
301
296
|
StrawberryType,
|
302
|
-
|
297
|
+
type[WithStrawberryObjectDefinition],
|
303
298
|
Literal[UNRESOLVED],
|
304
299
|
]:
|
305
300
|
return self.resolve_type()
|
@@ -316,7 +311,7 @@ class StrawberryField(dataclasses.Field):
|
|
316
311
|
|
317
312
|
# TODO: add this to arguments (and/or move it to StrawberryType)
|
318
313
|
@property
|
319
|
-
def type_params(self) ->
|
314
|
+
def type_params(self) -> list[TypeVar]:
|
320
315
|
if has_object_definition(self.type):
|
321
316
|
parameters = getattr(self.type, "__parameters__", None)
|
322
317
|
|
@@ -334,7 +329,7 @@ class StrawberryField(dataclasses.Field):
|
|
334
329
|
type_definition: Optional[StrawberryObjectDefinition] = None,
|
335
330
|
) -> Union[ # type: ignore [valid-type]
|
336
331
|
StrawberryType,
|
337
|
-
|
332
|
+
type[WithStrawberryObjectDefinition],
|
338
333
|
Literal[UNRESOLVED],
|
339
334
|
]:
|
340
335
|
# We return UNRESOLVED by default, which means this case will raise a
|
@@ -385,7 +380,7 @@ class StrawberryField(dataclasses.Field):
|
|
385
380
|
new_field = copy.copy(self)
|
386
381
|
|
387
382
|
override_type: Optional[
|
388
|
-
Union[StrawberryType,
|
383
|
+
Union[StrawberryType, type[WithStrawberryObjectDefinition]]
|
389
384
|
] = None
|
390
385
|
type_ = self.resolve_type()
|
391
386
|
if has_object_definition(type_):
|
@@ -431,13 +426,13 @@ def field(
|
|
431
426
|
is_subscription: bool = False,
|
432
427
|
description: Optional[str] = None,
|
433
428
|
init: Literal[False] = False,
|
434
|
-
permission_classes: Optional[
|
429
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
435
430
|
deprecation_reason: Optional[str] = None,
|
436
431
|
default: Any = dataclasses.MISSING,
|
437
432
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
438
433
|
metadata: Optional[Mapping[Any, Any]] = None,
|
439
434
|
directives: Optional[Sequence[object]] = (),
|
440
|
-
extensions: Optional[
|
435
|
+
extensions: Optional[list[FieldExtension]] = None,
|
441
436
|
graphql_type: Optional[Any] = None,
|
442
437
|
) -> T: ...
|
443
438
|
|
@@ -450,13 +445,13 @@ def field(
|
|
450
445
|
is_subscription: bool = False,
|
451
446
|
description: Optional[str] = None,
|
452
447
|
init: Literal[False] = False,
|
453
|
-
permission_classes: Optional[
|
448
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
454
449
|
deprecation_reason: Optional[str] = None,
|
455
450
|
default: Any = dataclasses.MISSING,
|
456
451
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
457
452
|
metadata: Optional[Mapping[Any, Any]] = None,
|
458
453
|
directives: Optional[Sequence[object]] = (),
|
459
|
-
extensions: Optional[
|
454
|
+
extensions: Optional[list[FieldExtension]] = None,
|
460
455
|
graphql_type: Optional[Any] = None,
|
461
456
|
) -> T: ...
|
462
457
|
|
@@ -468,13 +463,13 @@ def field(
|
|
468
463
|
is_subscription: bool = False,
|
469
464
|
description: Optional[str] = None,
|
470
465
|
init: Literal[True] = True,
|
471
|
-
permission_classes: Optional[
|
466
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
472
467
|
deprecation_reason: Optional[str] = None,
|
473
468
|
default: Any = dataclasses.MISSING,
|
474
469
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
475
470
|
metadata: Optional[Mapping[Any, Any]] = None,
|
476
471
|
directives: Optional[Sequence[object]] = (),
|
477
|
-
extensions: Optional[
|
472
|
+
extensions: Optional[list[FieldExtension]] = None,
|
478
473
|
graphql_type: Optional[Any] = None,
|
479
474
|
) -> Any: ...
|
480
475
|
|
@@ -486,13 +481,13 @@ def field(
|
|
486
481
|
name: Optional[str] = None,
|
487
482
|
is_subscription: bool = False,
|
488
483
|
description: Optional[str] = None,
|
489
|
-
permission_classes: Optional[
|
484
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
490
485
|
deprecation_reason: Optional[str] = None,
|
491
486
|
default: Any = dataclasses.MISSING,
|
492
487
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
493
488
|
metadata: Optional[Mapping[Any, Any]] = None,
|
494
489
|
directives: Optional[Sequence[object]] = (),
|
495
|
-
extensions: Optional[
|
490
|
+
extensions: Optional[list[FieldExtension]] = None,
|
496
491
|
graphql_type: Optional[Any] = None,
|
497
492
|
) -> StrawberryField: ...
|
498
493
|
|
@@ -504,13 +499,13 @@ def field(
|
|
504
499
|
name: Optional[str] = None,
|
505
500
|
is_subscription: bool = False,
|
506
501
|
description: Optional[str] = None,
|
507
|
-
permission_classes: Optional[
|
502
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
508
503
|
deprecation_reason: Optional[str] = None,
|
509
504
|
default: Any = dataclasses.MISSING,
|
510
505
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
511
506
|
metadata: Optional[Mapping[Any, Any]] = None,
|
512
507
|
directives: Optional[Sequence[object]] = (),
|
513
|
-
extensions: Optional[
|
508
|
+
extensions: Optional[list[FieldExtension]] = None,
|
514
509
|
graphql_type: Optional[Any] = None,
|
515
510
|
) -> StrawberryField: ...
|
516
511
|
|
@@ -521,13 +516,13 @@ def field(
|
|
521
516
|
name: Optional[str] = None,
|
522
517
|
is_subscription: bool = False,
|
523
518
|
description: Optional[str] = None,
|
524
|
-
permission_classes: Optional[
|
519
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
525
520
|
deprecation_reason: Optional[str] = None,
|
526
521
|
default: Any = dataclasses.MISSING,
|
527
522
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
528
523
|
metadata: Optional[Mapping[Any, Any]] = None,
|
529
524
|
directives: Optional[Sequence[object]] = (),
|
530
|
-
extensions: Optional[
|
525
|
+
extensions: Optional[list[FieldExtension]] = None,
|
531
526
|
graphql_type: Optional[Any] = None,
|
532
527
|
# This init parameter is used by PyRight to determine whether this field
|
533
528
|
# is added in the constructor or not. It is not used to change
|