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
@@ -8,20 +8,17 @@ from functools import cached_property
|
|
8
8
|
from inspect import isasyncgenfunction
|
9
9
|
from typing import (
|
10
10
|
TYPE_CHECKING,
|
11
|
+
Annotated,
|
11
12
|
Any,
|
12
13
|
Callable,
|
13
|
-
Dict,
|
14
14
|
Generic,
|
15
|
-
List,
|
16
|
-
Mapping,
|
17
15
|
NamedTuple,
|
18
16
|
Optional,
|
19
|
-
Tuple,
|
20
17
|
TypeVar,
|
21
18
|
Union,
|
22
19
|
cast,
|
23
20
|
)
|
24
|
-
from typing_extensions import
|
21
|
+
from typing_extensions import Protocol, get_origin
|
25
22
|
|
26
23
|
from strawberry.annotation import StrawberryAnnotation
|
27
24
|
from strawberry.exceptions import (
|
@@ -36,6 +33,7 @@ from strawberry.utils.typing import type_has_annotation
|
|
36
33
|
|
37
34
|
if TYPE_CHECKING:
|
38
35
|
import builtins
|
36
|
+
from collections.abc import Mapping
|
39
37
|
|
40
38
|
|
41
39
|
class Parameter(inspect.Parameter):
|
@@ -63,7 +61,7 @@ class Signature(inspect.Signature):
|
|
63
61
|
class ReservedParameterSpecification(Protocol):
|
64
62
|
def find(
|
65
63
|
self,
|
66
|
-
parameters:
|
64
|
+
parameters: tuple[inspect.Parameter, ...],
|
67
65
|
resolver: StrawberryResolver[Any],
|
68
66
|
) -> Optional[inspect.Parameter]:
|
69
67
|
"""Finds the reserved parameter from ``parameters``."""
|
@@ -74,7 +72,7 @@ class ReservedName(NamedTuple):
|
|
74
72
|
|
75
73
|
def find(
|
76
74
|
self,
|
77
|
-
parameters:
|
75
|
+
parameters: tuple[inspect.Parameter, ...],
|
78
76
|
resolver: StrawberryResolver[Any],
|
79
77
|
) -> Optional[inspect.Parameter]:
|
80
78
|
del resolver
|
@@ -86,7 +84,7 @@ class ReservedNameBoundParameter(NamedTuple):
|
|
86
84
|
|
87
85
|
def find(
|
88
86
|
self,
|
89
|
-
parameters:
|
87
|
+
parameters: tuple[inspect.Parameter, ...],
|
90
88
|
resolver: StrawberryResolver[Any],
|
91
89
|
) -> Optional[inspect.Parameter]:
|
92
90
|
del resolver
|
@@ -109,7 +107,7 @@ class ReservedType(NamedTuple):
|
|
109
107
|
|
110
108
|
def find(
|
111
109
|
self,
|
112
|
-
parameters:
|
110
|
+
parameters: tuple[inspect.Parameter, ...],
|
113
111
|
resolver: StrawberryResolver[Any],
|
114
112
|
) -> Optional[inspect.Parameter]:
|
115
113
|
# Go through all the types even after we've found one so we can
|
@@ -181,7 +179,7 @@ else:
|
|
181
179
|
|
182
180
|
|
183
181
|
class StrawberryResolver(Generic[T]):
|
184
|
-
RESERVED_PARAMSPEC:
|
182
|
+
RESERVED_PARAMSPEC: tuple[ReservedParameterSpecification, ...] = (
|
185
183
|
SELF_PARAMSPEC,
|
186
184
|
CLS_PARAMSPEC,
|
187
185
|
ROOT_PARAMSPEC,
|
@@ -218,7 +216,7 @@ class StrawberryResolver(Generic[T]):
|
|
218
216
|
@cached_property
|
219
217
|
def strawberry_annotations(
|
220
218
|
self,
|
221
|
-
) ->
|
219
|
+
) -> dict[inspect.Parameter, Union[StrawberryAnnotation, None]]:
|
222
220
|
return {
|
223
221
|
p: (
|
224
222
|
StrawberryAnnotation(p.annotation, namespace=self._namespace)
|
@@ -231,13 +229,13 @@ class StrawberryResolver(Generic[T]):
|
|
231
229
|
@cached_property
|
232
230
|
def reserved_parameters(
|
233
231
|
self,
|
234
|
-
) ->
|
232
|
+
) -> dict[ReservedParameterSpecification, Optional[inspect.Parameter]]:
|
235
233
|
"""Mapping of reserved parameter specification to parameter."""
|
236
234
|
parameters = tuple(self.signature.parameters.values())
|
237
235
|
return {spec: spec.find(parameters, self) for spec in self.RESERVED_PARAMSPEC}
|
238
236
|
|
239
237
|
@cached_property
|
240
|
-
def arguments(self) ->
|
238
|
+
def arguments(self) -> list[StrawberryArgument]:
|
241
239
|
"""Resolver arguments exposed in the GraphQL Schema."""
|
242
240
|
root_parameter = self.reserved_parameters.get(ROOT_PARAMSPEC)
|
243
241
|
parent_parameter = self.reserved_parameters.get(PARENT_PARAMSPEC)
|
@@ -258,8 +256,8 @@ class StrawberryResolver(Generic[T]):
|
|
258
256
|
|
259
257
|
parameters = self.signature.parameters.values()
|
260
258
|
reserved_parameters = set(self.reserved_parameters.values())
|
261
|
-
missing_annotations:
|
262
|
-
arguments:
|
259
|
+
missing_annotations: list[str] = []
|
260
|
+
arguments: list[StrawberryArgument] = []
|
263
261
|
user_parameters = (p for p in parameters if p not in reserved_parameters)
|
264
262
|
|
265
263
|
for param in user_parameters:
|
@@ -301,7 +299,7 @@ class StrawberryResolver(Generic[T]):
|
|
301
299
|
|
302
300
|
# TODO: consider deprecating
|
303
301
|
@cached_property
|
304
|
-
def annotations(self) ->
|
302
|
+
def annotations(self) -> dict[str, object]:
|
305
303
|
"""Annotations for the resolver.
|
306
304
|
|
307
305
|
Does not include special args defined in `RESERVED_PARAMSPEC` (e.g. self, root,
|
@@ -387,7 +385,7 @@ class StrawberryResolver(Generic[T]):
|
|
387
385
|
return other
|
388
386
|
|
389
387
|
@cached_property
|
390
|
-
def _namespace(self) ->
|
388
|
+
def _namespace(self) -> dict[str, Any]:
|
391
389
|
return sys.modules[self._unbound_wrapped_func.__module__].__dict__
|
392
390
|
|
393
391
|
@cached_property
|
strawberry/types/graphql.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
3
|
import enum
|
4
|
-
from typing import TYPE_CHECKING
|
4
|
+
from typing import TYPE_CHECKING
|
5
5
|
|
6
6
|
if TYPE_CHECKING:
|
7
7
|
from strawberry.http.types import HTTPMethod
|
@@ -13,7 +13,7 @@ class OperationType(enum.Enum):
|
|
13
13
|
SUBSCRIPTION = "subscription"
|
14
14
|
|
15
15
|
@staticmethod
|
16
|
-
def from_http(method: HTTPMethod) ->
|
16
|
+
def from_http(method: HTTPMethod) -> set[OperationType]:
|
17
17
|
if method == "GET":
|
18
18
|
return {
|
19
19
|
OperationType.QUERY,
|
strawberry/types/info.py
CHANGED
@@ -6,12 +6,8 @@ from functools import cached_property
|
|
6
6
|
from typing import (
|
7
7
|
TYPE_CHECKING,
|
8
8
|
Any,
|
9
|
-
Dict,
|
10
9
|
Generic,
|
11
|
-
List,
|
12
10
|
Optional,
|
13
|
-
Tuple,
|
14
|
-
Type,
|
15
11
|
Union,
|
16
12
|
)
|
17
13
|
from typing_extensions import TypeVar
|
@@ -72,7 +68,7 @@ class Info(Generic[ContextType, RootValueType]):
|
|
72
68
|
_raw_info: GraphQLResolveInfo
|
73
69
|
_field: StrawberryField
|
74
70
|
|
75
|
-
def __class_getitem__(cls, types: Union[type,
|
71
|
+
def __class_getitem__(cls, types: Union[type, tuple[type, ...]]) -> type[Info]:
|
76
72
|
"""Workaround for when passing only one type.
|
77
73
|
|
78
74
|
Python doesn't yet support directly passing only one type to a generic class
|
@@ -97,7 +93,7 @@ class Info(Generic[ContextType, RootValueType]):
|
|
97
93
|
return self._raw_info.schema._strawberry_schema # type: ignore
|
98
94
|
|
99
95
|
@property
|
100
|
-
def field_nodes(self) ->
|
96
|
+
def field_nodes(self) -> list[FieldNode]: # deprecated
|
101
97
|
warnings.warn(
|
102
98
|
"`info.field_nodes` is deprecated, use `selected_fields` instead",
|
103
99
|
DeprecationWarning,
|
@@ -107,7 +103,7 @@ class Info(Generic[ContextType, RootValueType]):
|
|
107
103
|
return self._raw_info.field_nodes
|
108
104
|
|
109
105
|
@cached_property
|
110
|
-
def selected_fields(self) ->
|
106
|
+
def selected_fields(self) -> list[Selection]:
|
111
107
|
"""The fields that were selected on the current field's type."""
|
112
108
|
info = self._raw_info
|
113
109
|
return convert_selections(info, info.field_nodes)
|
@@ -123,14 +119,14 @@ class Info(Generic[ContextType, RootValueType]):
|
|
123
119
|
return self._raw_info.root_value
|
124
120
|
|
125
121
|
@property
|
126
|
-
def variable_values(self) ->
|
122
|
+
def variable_values(self) -> dict[str, Any]:
|
127
123
|
"""The variable values passed to the query execution."""
|
128
124
|
return self._raw_info.variable_values
|
129
125
|
|
130
126
|
@property
|
131
127
|
def return_type(
|
132
128
|
self,
|
133
|
-
) -> Optional[Union[
|
129
|
+
) -> Optional[Union[type[WithStrawberryObjectDefinition], StrawberryType]]:
|
134
130
|
"""The return type of the current field being resolved."""
|
135
131
|
return self._field.type
|
136
132
|
|
strawberry/types/lazy_type.py
CHANGED
@@ -9,8 +9,6 @@ from typing import (
|
|
9
9
|
ForwardRef,
|
10
10
|
Generic,
|
11
11
|
Optional,
|
12
|
-
Tuple,
|
13
|
-
Type,
|
14
12
|
TypeVar,
|
15
13
|
Union,
|
16
14
|
cast,
|
@@ -36,7 +34,7 @@ class LazyType(Generic[TypeName, Module]):
|
|
36
34
|
module: str
|
37
35
|
package: Optional[str] = None
|
38
36
|
|
39
|
-
def __class_getitem__(cls, params:
|
37
|
+
def __class_getitem__(cls, params: tuple[str, str]) -> "Self":
|
40
38
|
warnings.warn(
|
41
39
|
(
|
42
40
|
"LazyType is deprecated, use "
|
@@ -61,7 +59,7 @@ class LazyType(Generic[TypeName, Module]):
|
|
61
59
|
def __or__(self, other: Other) -> object:
|
62
60
|
return Union[self, other]
|
63
61
|
|
64
|
-
def resolve_type(self) ->
|
62
|
+
def resolve_type(self) -> type[Any]:
|
65
63
|
module = importlib.import_module(self.module, self.package)
|
66
64
|
main_module = sys.modules.get("__main__", None)
|
67
65
|
if main_module:
|
@@ -84,7 +82,7 @@ class LazyType(Generic[TypeName, Module]):
|
|
84
82
|
return module.__dict__[self.type_name]
|
85
83
|
|
86
84
|
# this empty call method allows LazyTypes to be used in generic types
|
87
|
-
# for example:
|
85
|
+
# for example: list[LazyType["A", "module"]]
|
88
86
|
|
89
87
|
def __call__(self) -> None: # pragma: no cover
|
90
88
|
return None
|
strawberry/types/mutation.py
CHANGED
@@ -5,11 +5,7 @@ from typing import (
|
|
5
5
|
TYPE_CHECKING,
|
6
6
|
Any,
|
7
7
|
Callable,
|
8
|
-
List,
|
9
|
-
Mapping,
|
10
8
|
Optional,
|
11
|
-
Sequence,
|
12
|
-
Type,
|
13
9
|
Union,
|
14
10
|
overload,
|
15
11
|
)
|
@@ -25,6 +21,7 @@ from strawberry.types.field import (
|
|
25
21
|
)
|
26
22
|
|
27
23
|
if TYPE_CHECKING:
|
24
|
+
from collections.abc import Mapping, Sequence
|
28
25
|
from typing_extensions import Literal
|
29
26
|
|
30
27
|
from strawberry.extensions.field_extension import FieldExtension
|
@@ -41,13 +38,13 @@ def mutation(
|
|
41
38
|
name: Optional[str] = None,
|
42
39
|
description: Optional[str] = None,
|
43
40
|
init: Literal[False] = False,
|
44
|
-
permission_classes: Optional[
|
41
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
45
42
|
deprecation_reason: Optional[str] = None,
|
46
43
|
default: Any = dataclasses.MISSING,
|
47
44
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
48
45
|
metadata: Optional[Mapping[Any, Any]] = None,
|
49
46
|
directives: Optional[Sequence[object]] = (),
|
50
|
-
extensions: Optional[
|
47
|
+
extensions: Optional[list[FieldExtension]] = None,
|
51
48
|
graphql_type: Optional[Any] = None,
|
52
49
|
) -> T: ...
|
53
50
|
|
@@ -59,13 +56,13 @@ def mutation(
|
|
59
56
|
name: Optional[str] = None,
|
60
57
|
description: Optional[str] = None,
|
61
58
|
init: Literal[False] = False,
|
62
|
-
permission_classes: Optional[
|
59
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
63
60
|
deprecation_reason: Optional[str] = None,
|
64
61
|
default: Any = dataclasses.MISSING,
|
65
62
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
66
63
|
metadata: Optional[Mapping[Any, Any]] = None,
|
67
64
|
directives: Optional[Sequence[object]] = (),
|
68
|
-
extensions: Optional[
|
65
|
+
extensions: Optional[list[FieldExtension]] = None,
|
69
66
|
graphql_type: Optional[Any] = None,
|
70
67
|
) -> T: ...
|
71
68
|
|
@@ -76,13 +73,13 @@ def mutation(
|
|
76
73
|
name: Optional[str] = None,
|
77
74
|
description: Optional[str] = None,
|
78
75
|
init: Literal[True] = True,
|
79
|
-
permission_classes: Optional[
|
76
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
80
77
|
deprecation_reason: Optional[str] = None,
|
81
78
|
default: Any = dataclasses.MISSING,
|
82
79
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
83
80
|
metadata: Optional[Mapping[Any, Any]] = None,
|
84
81
|
directives: Optional[Sequence[object]] = (),
|
85
|
-
extensions: Optional[
|
82
|
+
extensions: Optional[list[FieldExtension]] = None,
|
86
83
|
graphql_type: Optional[Any] = None,
|
87
84
|
) -> Any: ...
|
88
85
|
|
@@ -93,13 +90,13 @@ def mutation(
|
|
93
90
|
*,
|
94
91
|
name: Optional[str] = None,
|
95
92
|
description: Optional[str] = None,
|
96
|
-
permission_classes: Optional[
|
93
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
97
94
|
deprecation_reason: Optional[str] = None,
|
98
95
|
default: Any = dataclasses.MISSING,
|
99
96
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
100
97
|
metadata: Optional[Mapping[Any, Any]] = None,
|
101
98
|
directives: Optional[Sequence[object]] = (),
|
102
|
-
extensions: Optional[
|
99
|
+
extensions: Optional[list[FieldExtension]] = None,
|
103
100
|
graphql_type: Optional[Any] = None,
|
104
101
|
) -> StrawberryField: ...
|
105
102
|
|
@@ -110,13 +107,13 @@ def mutation(
|
|
110
107
|
*,
|
111
108
|
name: Optional[str] = None,
|
112
109
|
description: Optional[str] = None,
|
113
|
-
permission_classes: Optional[
|
110
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
114
111
|
deprecation_reason: Optional[str] = None,
|
115
112
|
default: Any = dataclasses.MISSING,
|
116
113
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
117
114
|
metadata: Optional[Mapping[Any, Any]] = None,
|
118
115
|
directives: Optional[Sequence[object]] = (),
|
119
|
-
extensions: Optional[
|
116
|
+
extensions: Optional[list[FieldExtension]] = None,
|
120
117
|
graphql_type: Optional[Any] = None,
|
121
118
|
) -> StrawberryField: ...
|
122
119
|
|
@@ -126,13 +123,13 @@ def mutation(
|
|
126
123
|
*,
|
127
124
|
name: Optional[str] = None,
|
128
125
|
description: Optional[str] = None,
|
129
|
-
permission_classes: Optional[
|
126
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
130
127
|
deprecation_reason: Optional[str] = None,
|
131
128
|
default: Any = dataclasses.MISSING,
|
132
129
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
133
130
|
metadata: Optional[Mapping[Any, Any]] = None,
|
134
131
|
directives: Optional[Sequence[object]] = (),
|
135
|
-
extensions: Optional[
|
132
|
+
extensions: Optional[list[FieldExtension]] = None,
|
136
133
|
graphql_type: Optional[Any] = None,
|
137
134
|
# This init parameter is used by PyRight to determine whether this field
|
138
135
|
# is added in the constructor or not. It is not used to change
|
@@ -201,13 +198,13 @@ def subscription(
|
|
201
198
|
name: Optional[str] = None,
|
202
199
|
description: Optional[str] = None,
|
203
200
|
init: Literal[False] = False,
|
204
|
-
permission_classes: Optional[
|
201
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
205
202
|
deprecation_reason: Optional[str] = None,
|
206
203
|
default: Any = dataclasses.MISSING,
|
207
204
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
208
205
|
metadata: Optional[Mapping[Any, Any]] = None,
|
209
206
|
directives: Optional[Sequence[object]] = (),
|
210
|
-
extensions: Optional[
|
207
|
+
extensions: Optional[list[FieldExtension]] = None,
|
211
208
|
graphql_type: Optional[Any] = None,
|
212
209
|
) -> T: ...
|
213
210
|
|
@@ -219,13 +216,13 @@ def subscription(
|
|
219
216
|
name: Optional[str] = None,
|
220
217
|
description: Optional[str] = None,
|
221
218
|
init: Literal[False] = False,
|
222
|
-
permission_classes: Optional[
|
219
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
223
220
|
deprecation_reason: Optional[str] = None,
|
224
221
|
default: Any = dataclasses.MISSING,
|
225
222
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
226
223
|
metadata: Optional[Mapping[Any, Any]] = None,
|
227
224
|
directives: Optional[Sequence[object]] = (),
|
228
|
-
extensions: Optional[
|
225
|
+
extensions: Optional[list[FieldExtension]] = None,
|
229
226
|
graphql_type: Optional[Any] = None,
|
230
227
|
) -> T: ...
|
231
228
|
|
@@ -236,13 +233,13 @@ def subscription(
|
|
236
233
|
name: Optional[str] = None,
|
237
234
|
description: Optional[str] = None,
|
238
235
|
init: Literal[True] = True,
|
239
|
-
permission_classes: Optional[
|
236
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
240
237
|
deprecation_reason: Optional[str] = None,
|
241
238
|
default: Any = dataclasses.MISSING,
|
242
239
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
243
240
|
metadata: Optional[Mapping[Any, Any]] = None,
|
244
241
|
directives: Optional[Sequence[object]] = (),
|
245
|
-
extensions: Optional[
|
242
|
+
extensions: Optional[list[FieldExtension]] = None,
|
246
243
|
graphql_type: Optional[Any] = None,
|
247
244
|
) -> Any: ...
|
248
245
|
|
@@ -253,13 +250,13 @@ def subscription(
|
|
253
250
|
*,
|
254
251
|
name: Optional[str] = None,
|
255
252
|
description: Optional[str] = None,
|
256
|
-
permission_classes: Optional[
|
253
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
257
254
|
deprecation_reason: Optional[str] = None,
|
258
255
|
default: Any = dataclasses.MISSING,
|
259
256
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
260
257
|
metadata: Optional[Mapping[Any, Any]] = None,
|
261
258
|
directives: Optional[Sequence[object]] = (),
|
262
|
-
extensions: Optional[
|
259
|
+
extensions: Optional[list[FieldExtension]] = None,
|
263
260
|
graphql_type: Optional[Any] = None,
|
264
261
|
) -> StrawberryField: ...
|
265
262
|
|
@@ -270,13 +267,13 @@ def subscription(
|
|
270
267
|
*,
|
271
268
|
name: Optional[str] = None,
|
272
269
|
description: Optional[str] = None,
|
273
|
-
permission_classes: Optional[
|
270
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
274
271
|
deprecation_reason: Optional[str] = None,
|
275
272
|
default: Any = dataclasses.MISSING,
|
276
273
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
277
274
|
metadata: Optional[Mapping[Any, Any]] = None,
|
278
275
|
directives: Optional[Sequence[object]] = (),
|
279
|
-
extensions: Optional[
|
276
|
+
extensions: Optional[list[FieldExtension]] = None,
|
280
277
|
graphql_type: Optional[Any] = None,
|
281
278
|
) -> StrawberryField: ...
|
282
279
|
|
@@ -286,13 +283,13 @@ def subscription(
|
|
286
283
|
*,
|
287
284
|
name: Optional[str] = None,
|
288
285
|
description: Optional[str] = None,
|
289
|
-
permission_classes: Optional[
|
286
|
+
permission_classes: Optional[list[type[BasePermission]]] = None,
|
290
287
|
deprecation_reason: Optional[str] = None,
|
291
288
|
default: Any = dataclasses.MISSING,
|
292
289
|
default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
|
293
290
|
metadata: Optional[Mapping[Any, Any]] = None,
|
294
291
|
directives: Optional[Sequence[object]] = (),
|
295
|
-
extensions: Optional[
|
292
|
+
extensions: Optional[list[FieldExtension]] = None,
|
296
293
|
graphql_type: Optional[Any] = None,
|
297
294
|
init: Literal[True, False, None] = None,
|
298
295
|
) -> Any:
|
strawberry/types/nodes.py
CHANGED
@@ -12,7 +12,7 @@ Note Python dicts maintain ordering (for all supported versions).
|
|
12
12
|
from __future__ import annotations
|
13
13
|
|
14
14
|
import dataclasses
|
15
|
-
from typing import TYPE_CHECKING, Any,
|
15
|
+
from typing import TYPE_CHECKING, Any, Optional, Union
|
16
16
|
|
17
17
|
from graphql.language import FieldNode as GQLFieldNode
|
18
18
|
from graphql.language import FragmentSpreadNode as GQLFragmentSpreadNode
|
@@ -22,12 +22,14 @@ from graphql.language import ObjectValueNode as GQLObjectValueNode
|
|
22
22
|
from graphql.language import VariableNode as GQLVariableNode
|
23
23
|
|
24
24
|
if TYPE_CHECKING:
|
25
|
+
from collections.abc import Collection, Iterable
|
26
|
+
|
25
27
|
from graphql import GraphQLResolveInfo
|
26
28
|
from graphql.language import ArgumentNode as GQLArgumentNode
|
27
29
|
from graphql.language import DirectiveNode as GQLDirectiveNode
|
28
30
|
from graphql.language import ValueNode as GQLValueNode
|
29
|
-
Arguments =
|
30
|
-
Directives =
|
31
|
+
Arguments = dict[str, Any]
|
32
|
+
Directives = dict[str, Arguments]
|
31
33
|
Selection = Union["SelectedField", "FragmentSpread", "InlineFragment"]
|
32
34
|
|
33
35
|
|
@@ -62,9 +64,9 @@ def convert_directives(
|
|
62
64
|
|
63
65
|
def convert_selections(
|
64
66
|
info: GraphQLResolveInfo, field_nodes: Collection[GQLFieldNode]
|
65
|
-
) ->
|
67
|
+
) -> list[Selection]:
|
66
68
|
"""Return typed `Selection` based on node type."""
|
67
|
-
selections:
|
69
|
+
selections: list[Selection] = []
|
68
70
|
for node in field_nodes:
|
69
71
|
if isinstance(node, GQLFieldNode):
|
70
72
|
selections.append(SelectedField.from_node(info, node))
|
@@ -85,7 +87,7 @@ class FragmentSpread:
|
|
85
87
|
name: str
|
86
88
|
type_condition: str
|
87
89
|
directives: Directives
|
88
|
-
selections:
|
90
|
+
selections: list[Selection]
|
89
91
|
|
90
92
|
@classmethod
|
91
93
|
def from_node(
|
@@ -111,7 +113,7 @@ class InlineFragment:
|
|
111
113
|
"""Wrapper for a InlineFragmentNode."""
|
112
114
|
|
113
115
|
type_condition: str
|
114
|
-
selections:
|
116
|
+
selections: list[Selection]
|
115
117
|
directives: Directives
|
116
118
|
|
117
119
|
@classmethod
|
@@ -136,7 +138,7 @@ class SelectedField:
|
|
136
138
|
name: str
|
137
139
|
directives: Directives
|
138
140
|
arguments: Arguments
|
139
|
-
selections:
|
141
|
+
selections: list[Selection]
|
140
142
|
alias: Optional[str] = None
|
141
143
|
|
142
144
|
@classmethod
|
@@ -152,4 +154,4 @@ class SelectedField:
|
|
152
154
|
)
|
153
155
|
|
154
156
|
|
155
|
-
__all__ = ["
|
157
|
+
__all__ = ["FragmentSpread", "InlineFragment", "SelectedField", "convert_selections"]
|
strawberry/types/object_type.py
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
+
import builtins
|
1
2
|
import dataclasses
|
2
3
|
import inspect
|
3
4
|
import sys
|
4
5
|
import types
|
6
|
+
from collections.abc import Sequence
|
5
7
|
from typing import (
|
6
8
|
Any,
|
7
9
|
Callable,
|
8
|
-
Dict,
|
9
|
-
List,
|
10
10
|
Optional,
|
11
|
-
Sequence,
|
12
|
-
Type,
|
13
11
|
TypeVar,
|
14
12
|
Union,
|
15
13
|
overload,
|
@@ -29,11 +27,11 @@ from .base import StrawberryObjectDefinition
|
|
29
27
|
from .field import StrawberryField, field
|
30
28
|
from .type_resolver import _get_fields
|
31
29
|
|
32
|
-
T = TypeVar("T", bound=
|
30
|
+
T = TypeVar("T", bound=builtins.type)
|
33
31
|
|
34
32
|
|
35
|
-
def _get_interfaces(cls:
|
36
|
-
interfaces:
|
33
|
+
def _get_interfaces(cls: builtins.type[Any]) -> list[StrawberryObjectDefinition]:
|
34
|
+
interfaces: list[StrawberryObjectDefinition] = []
|
37
35
|
for base in cls.__mro__[1:]: # Exclude current class
|
38
36
|
type_definition = get_object_definition(base)
|
39
37
|
if type_definition and type_definition.is_interface:
|
@@ -42,7 +40,7 @@ def _get_interfaces(cls: Type[Any]) -> List[StrawberryObjectDefinition]:
|
|
42
40
|
return interfaces
|
43
41
|
|
44
42
|
|
45
|
-
def _check_field_annotations(cls:
|
43
|
+
def _check_field_annotations(cls: builtins.type[Any]) -> None:
|
46
44
|
"""Are any of the dataclass Fields missing type annotations?
|
47
45
|
|
48
46
|
This is similar to the check that dataclasses do during creation, but allows us to
|
@@ -100,12 +98,12 @@ def _check_field_annotations(cls: Type[Any]) -> None:
|
|
100
98
|
raise MissingFieldAnnotationError(field_name, cls)
|
101
99
|
|
102
100
|
|
103
|
-
def _wrap_dataclass(cls:
|
101
|
+
def _wrap_dataclass(cls: builtins.type[T]) -> builtins.type[T]:
|
104
102
|
"""Wrap a strawberry.type class with a dataclass and check for any issues before doing so."""
|
105
103
|
# Ensure all Fields have been properly type-annotated
|
106
104
|
_check_field_annotations(cls)
|
107
105
|
|
108
|
-
dclass_kwargs:
|
106
|
+
dclass_kwargs: dict[str, bool] = {}
|
109
107
|
|
110
108
|
# Python 3.10 introduces the kw_only param. If we're on an older version
|
111
109
|
# then generate our own custom init function
|
@@ -133,7 +131,7 @@ def _process_type(
|
|
133
131
|
description: Optional[str] = None,
|
134
132
|
directives: Optional[Sequence[object]] = (),
|
135
133
|
extend: bool = False,
|
136
|
-
original_type_annotations: Optional[
|
134
|
+
original_type_annotations: Optional[dict[str, Any]] = None,
|
137
135
|
) -> T:
|
138
136
|
name = name or to_camel_case(cls.__name__)
|
139
137
|
original_type_annotations = original_type_annotations or {}
|
@@ -143,7 +141,7 @@ def _process_type(
|
|
143
141
|
is_type_of = getattr(cls, "is_type_of", None)
|
144
142
|
resolve_type = getattr(cls, "resolve_type", None)
|
145
143
|
|
146
|
-
cls.__strawberry_definition__ = StrawberryObjectDefinition(
|
144
|
+
cls.__strawberry_definition__ = StrawberryObjectDefinition( # type: ignore[attr-defined]
|
147
145
|
name=name,
|
148
146
|
is_input=is_input,
|
149
147
|
is_interface=is_interface,
|
@@ -159,7 +157,7 @@ def _process_type(
|
|
159
157
|
# TODO: remove when deprecating _type_definition
|
160
158
|
DeprecatedDescriptor(
|
161
159
|
DEPRECATION_MESSAGES._TYPE_DEFINITION,
|
162
|
-
cls.__strawberry_definition__,
|
160
|
+
cls.__strawberry_definition__, # type: ignore[attr-defined]
|
163
161
|
"_type_definition",
|
164
162
|
).inject(cls)
|
165
163
|
|
@@ -279,7 +277,7 @@ def type(
|
|
279
277
|
# >>> class Query:
|
280
278
|
# >>> a: int = strawberry.field(graphql_type=str)
|
281
279
|
# so we need to extract the information before running `_wrap_dataclass`
|
282
|
-
original_type_annotations:
|
280
|
+
original_type_annotations: dict[str, Any] = {}
|
283
281
|
|
284
282
|
annotations = getattr(cls, "__annotations__", {})
|
285
283
|
|
@@ -460,7 +458,7 @@ def interface(
|
|
460
458
|
)
|
461
459
|
|
462
460
|
|
463
|
-
def asdict(obj: Any) ->
|
461
|
+
def asdict(obj: Any) -> dict[str, object]:
|
464
462
|
"""Convert a strawberry object into a dictionary.
|
465
463
|
|
466
464
|
This wraps the dataclasses.asdict function to strawberry.
|
@@ -489,8 +487,8 @@ def asdict(obj: Any) -> Dict[str, object]:
|
|
489
487
|
|
490
488
|
__all__ = [
|
491
489
|
"StrawberryObjectDefinition",
|
490
|
+
"asdict",
|
492
491
|
"input",
|
493
492
|
"interface",
|
494
493
|
"type",
|
495
|
-
"asdict",
|
496
494
|
]
|
strawberry/types/private.py
CHANGED
strawberry/types/scalar.py
CHANGED
@@ -6,8 +6,6 @@ from typing import (
|
|
6
6
|
TYPE_CHECKING,
|
7
7
|
Any,
|
8
8
|
Callable,
|
9
|
-
Iterable,
|
10
|
-
Mapping,
|
11
9
|
NewType,
|
12
10
|
Optional,
|
13
11
|
TypeVar,
|
@@ -20,6 +18,8 @@ from strawberry.types.base import StrawberryType
|
|
20
18
|
from strawberry.utils.str_converters import to_camel_case
|
21
19
|
|
22
20
|
if TYPE_CHECKING:
|
21
|
+
from collections.abc import Iterable, Mapping
|
22
|
+
|
23
23
|
from graphql import GraphQLScalarType
|
24
24
|
|
25
25
|
|