strawberry-graphql 0.275.7__py3-none-any.whl → 0.284.3__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.
Potentially problematic release.
This version of strawberry-graphql might be problematic. Click here for more details.
- strawberry/__init__.py +2 -0
- strawberry/aiohttp/test/client.py +8 -15
- strawberry/aiohttp/views.py +15 -64
- strawberry/annotation.py +70 -25
- strawberry/asgi/__init__.py +22 -56
- strawberry/asgi/test/client.py +6 -6
- strawberry/chalice/views.py +13 -79
- strawberry/channels/handlers/base.py +7 -8
- strawberry/channels/handlers/http_handler.py +50 -32
- strawberry/channels/handlers/ws_handler.py +12 -14
- strawberry/channels/router.py +3 -4
- strawberry/channels/testing.py +7 -9
- strawberry/cli/__init__.py +7 -6
- strawberry/cli/commands/codegen.py +7 -7
- strawberry/cli/commands/dev.py +72 -0
- strawberry/cli/commands/schema_codegen.py +1 -2
- strawberry/cli/commands/server.py +3 -44
- strawberry/cli/commands/upgrade/__init__.py +3 -3
- strawberry/cli/commands/upgrade/_run_codemod.py +2 -2
- strawberry/cli/constants.py +1 -2
- strawberry/cli/{debug_server.py → dev_server.py} +3 -7
- strawberry/codegen/plugins/print_operation.py +2 -2
- strawberry/codegen/plugins/python.py +2 -2
- strawberry/codegen/query_codegen.py +20 -30
- strawberry/codegen/types.py +32 -32
- strawberry/codemods/__init__.py +9 -0
- strawberry/codemods/annotated_unions.py +2 -2
- strawberry/codemods/maybe_optional.py +118 -0
- strawberry/dataloader.py +28 -24
- strawberry/directive.py +6 -7
- strawberry/django/test/client.py +3 -3
- strawberry/django/views.py +21 -91
- strawberry/exceptions/__init__.py +4 -4
- strawberry/exceptions/conflicting_arguments.py +2 -2
- strawberry/exceptions/duplicated_type_name.py +4 -4
- strawberry/exceptions/exception.py +3 -3
- strawberry/exceptions/handler.py +8 -7
- strawberry/exceptions/invalid_argument_type.py +2 -2
- strawberry/exceptions/invalid_superclass_interface.py +2 -2
- strawberry/exceptions/invalid_union_type.py +4 -4
- strawberry/exceptions/missing_arguments_annotations.py +2 -2
- strawberry/exceptions/missing_dependencies.py +2 -4
- strawberry/exceptions/missing_field_annotation.py +2 -2
- strawberry/exceptions/missing_return_annotation.py +2 -2
- strawberry/exceptions/object_is_not_a_class.py +2 -2
- strawberry/exceptions/object_is_not_an_enum.py +2 -2
- strawberry/exceptions/permission_fail_silently_requires_optional.py +2 -2
- strawberry/exceptions/private_strawberry_field.py +2 -2
- strawberry/exceptions/scalar_already_registered.py +2 -2
- strawberry/exceptions/syntax.py +3 -3
- strawberry/exceptions/unresolved_field_type.py +2 -2
- strawberry/exceptions/utils/source_finder.py +25 -25
- strawberry/experimental/pydantic/_compat.py +8 -7
- strawberry/experimental/pydantic/conversion.py +2 -2
- strawberry/experimental/pydantic/conversion_types.py +2 -2
- strawberry/experimental/pydantic/error_type.py +10 -12
- strawberry/experimental/pydantic/fields.py +9 -15
- strawberry/experimental/pydantic/object_type.py +17 -25
- strawberry/experimental/pydantic/utils.py +1 -2
- strawberry/ext/mypy_plugin.py +12 -14
- strawberry/extensions/base_extension.py +2 -1
- strawberry/extensions/context.py +13 -18
- strawberry/extensions/directives.py +9 -3
- strawberry/extensions/field_extension.py +4 -4
- strawberry/extensions/mask_errors.py +24 -13
- strawberry/extensions/max_aliases.py +1 -3
- strawberry/extensions/parser_cache.py +1 -2
- strawberry/extensions/query_depth_limiter.py +18 -14
- strawberry/extensions/runner.py +2 -2
- strawberry/extensions/tracing/apollo.py +3 -3
- strawberry/extensions/tracing/datadog.py +3 -3
- strawberry/extensions/tracing/opentelemetry.py +6 -8
- strawberry/extensions/tracing/utils.py +3 -1
- strawberry/extensions/utils.py +2 -2
- strawberry/extensions/validation_cache.py +2 -3
- strawberry/fastapi/context.py +6 -6
- strawberry/fastapi/router.py +43 -42
- strawberry/federation/argument.py +4 -5
- strawberry/federation/enum.py +18 -21
- strawberry/federation/field.py +94 -97
- strawberry/federation/object_type.py +56 -58
- strawberry/federation/scalar.py +27 -35
- strawberry/federation/schema.py +15 -16
- strawberry/federation/schema_directive.py +7 -6
- strawberry/federation/schema_directives.py +11 -11
- strawberry/federation/union.py +4 -4
- strawberry/flask/views.py +16 -85
- strawberry/http/__init__.py +30 -20
- strawberry/http/async_base_view.py +208 -89
- strawberry/http/base.py +28 -11
- strawberry/http/exceptions.py +5 -7
- strawberry/http/ides.py +2 -3
- strawberry/http/sync_base_view.py +115 -69
- strawberry/http/types.py +3 -3
- strawberry/litestar/controller.py +43 -77
- strawberry/permission.py +4 -6
- strawberry/printer/ast_from_value.py +3 -5
- strawberry/printer/printer.py +18 -15
- strawberry/quart/views.py +16 -48
- strawberry/relay/exceptions.py +4 -4
- strawberry/relay/fields.py +33 -32
- strawberry/relay/types.py +32 -35
- strawberry/relay/utils.py +11 -23
- strawberry/resolvers.py +2 -1
- strawberry/sanic/context.py +1 -0
- strawberry/sanic/utils.py +3 -3
- strawberry/sanic/views.py +15 -54
- strawberry/scalars.py +2 -2
- strawberry/schema/_graphql_core.py +55 -0
- strawberry/schema/base.py +32 -33
- strawberry/schema/compat.py +9 -9
- strawberry/schema/config.py +10 -1
- strawberry/schema/exceptions.py +1 -3
- strawberry/schema/name_converter.py +9 -8
- strawberry/schema/schema.py +133 -100
- strawberry/schema/schema_converter.py +96 -58
- strawberry/schema/types/base_scalars.py +1 -1
- strawberry/schema/types/concrete_type.py +5 -5
- strawberry/schema/validation_rules/maybe_null.py +136 -0
- strawberry/schema_codegen/__init__.py +3 -3
- strawberry/schema_directive.py +7 -6
- strawberry/static/graphiql.html +5 -5
- strawberry/streamable.py +35 -0
- strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py +5 -16
- strawberry/subscriptions/protocols/graphql_transport_ws/types.py +20 -20
- strawberry/subscriptions/protocols/graphql_ws/handlers.py +5 -12
- strawberry/subscriptions/protocols/graphql_ws/types.py +14 -14
- strawberry/test/client.py +18 -18
- strawberry/tools/create_type.py +2 -3
- strawberry/types/arguments.py +41 -28
- strawberry/types/auto.py +3 -4
- strawberry/types/base.py +25 -27
- strawberry/types/enum.py +22 -25
- strawberry/types/execution.py +21 -16
- strawberry/types/field.py +109 -130
- strawberry/types/fields/resolver.py +19 -21
- strawberry/types/info.py +5 -11
- strawberry/types/lazy_type.py +2 -3
- strawberry/types/maybe.py +12 -3
- strawberry/types/mutation.py +115 -118
- strawberry/types/nodes.py +2 -2
- strawberry/types/object_type.py +43 -63
- strawberry/types/scalar.py +37 -43
- strawberry/types/union.py +12 -14
- strawberry/utils/aio.py +12 -9
- strawberry/utils/await_maybe.py +3 -3
- strawberry/utils/deprecations.py +2 -2
- strawberry/utils/importer.py +1 -2
- strawberry/utils/inspect.py +4 -6
- strawberry/utils/logging.py +2 -2
- strawberry/utils/operation.py +4 -4
- strawberry/utils/typing.py +18 -83
- {strawberry_graphql-0.275.7.dist-info → strawberry_graphql-0.284.3.dist-info}/METADATA +14 -8
- strawberry_graphql-0.284.3.dist-info/RECORD +243 -0
- {strawberry_graphql-0.275.7.dist-info → strawberry_graphql-0.284.3.dist-info}/WHEEL +1 -1
- strawberry/utils/dataclasses.py +0 -37
- strawberry/utils/debug.py +0 -46
- strawberry/utils/graphql_lexer.py +0 -35
- strawberry_graphql-0.275.7.dist-info/RECORD +0 -241
- {strawberry_graphql-0.275.7.dist-info → strawberry_graphql-0.284.3.dist-info}/entry_points.txt +0 -0
- {strawberry_graphql-0.275.7.dist-info → strawberry_graphql-0.284.3.dist-info/licenses}/LICENSE +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from functools import cached_property
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
5
|
|
|
6
6
|
from strawberry.types.base import get_object_definition
|
|
7
7
|
|
|
@@ -55,7 +55,7 @@ class InvalidArgumentTypeError(StrawberryException):
|
|
|
55
55
|
)
|
|
56
56
|
|
|
57
57
|
@cached_property
|
|
58
|
-
def exception_source(self) ->
|
|
58
|
+
def exception_source(self) -> ExceptionSource | None:
|
|
59
59
|
if self.function is None:
|
|
60
60
|
return None # pragma: no cover
|
|
61
61
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from functools import cached_property
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
5
|
|
|
6
6
|
from .exception import StrawberryException
|
|
7
7
|
from .utils.source_finder import SourceFinder
|
|
@@ -36,6 +36,6 @@ class InvalidSuperclassInterfaceError(StrawberryException):
|
|
|
36
36
|
super().__init__(self.message)
|
|
37
37
|
|
|
38
38
|
@cached_property
|
|
39
|
-
def exception_source(self) ->
|
|
39
|
+
def exception_source(self) -> ExceptionSource | None:
|
|
40
40
|
source_finder = SourceFinder()
|
|
41
41
|
return source_finder.find_class_from_object(self.cls)
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from functools import cached_property
|
|
4
4
|
from inspect import getframeinfo, stack
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import TYPE_CHECKING
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
7
|
|
|
8
8
|
from strawberry.exceptions.utils.source_finder import SourceFinder
|
|
9
9
|
|
|
@@ -24,7 +24,7 @@ class InvalidUnionTypeError(StrawberryException):
|
|
|
24
24
|
self,
|
|
25
25
|
union_name: str,
|
|
26
26
|
invalid_type: object,
|
|
27
|
-
union_definition:
|
|
27
|
+
union_definition: StrawberryUnion | None = None,
|
|
28
28
|
) -> None:
|
|
29
29
|
from strawberry.types.base import StrawberryList
|
|
30
30
|
from strawberry.types.scalar import ScalarWrapper
|
|
@@ -58,7 +58,7 @@ class InvalidUnionTypeError(StrawberryException):
|
|
|
58
58
|
self.annotation_message = "invalid type here"
|
|
59
59
|
|
|
60
60
|
@cached_property
|
|
61
|
-
def exception_source(self) ->
|
|
61
|
+
def exception_source(self) -> ExceptionSource | None:
|
|
62
62
|
source_finder = SourceFinder()
|
|
63
63
|
|
|
64
64
|
if self.union_definition:
|
|
@@ -100,7 +100,7 @@ class InvalidTypeForUnionMergeError(StrawberryException):
|
|
|
100
100
|
self.annotation_message = "invalid type here"
|
|
101
101
|
|
|
102
102
|
@cached_property
|
|
103
|
-
def exception_source(self) ->
|
|
103
|
+
def exception_source(self) -> ExceptionSource | None:
|
|
104
104
|
source_finder = SourceFinder()
|
|
105
105
|
|
|
106
106
|
return source_finder.find_union_merge(self.union, self.other, frame=self.frame)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from functools import cached_property
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
5
|
|
|
6
6
|
from .exception import StrawberryException
|
|
7
7
|
from .utils.source_finder import SourceFinder
|
|
@@ -52,7 +52,7 @@ class MissingArgumentsAnnotationsError(StrawberryException):
|
|
|
52
52
|
return f'arguments "{head}" and "{arguments[-1]}"'
|
|
53
53
|
|
|
54
54
|
@cached_property
|
|
55
|
-
def exception_source(self) ->
|
|
55
|
+
def exception_source(self) -> ExceptionSource | None:
|
|
56
56
|
if self.function is None:
|
|
57
57
|
return None # pragma: no cover
|
|
58
58
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import Optional
|
|
4
|
-
|
|
5
3
|
|
|
6
4
|
class MissingOptionalDependenciesError(Exception):
|
|
7
5
|
"""Some optional dependencies that are required for a particular task are missing."""
|
|
@@ -9,8 +7,8 @@ class MissingOptionalDependenciesError(Exception):
|
|
|
9
7
|
def __init__(
|
|
10
8
|
self,
|
|
11
9
|
*,
|
|
12
|
-
packages:
|
|
13
|
-
extras:
|
|
10
|
+
packages: list[str] | None = None,
|
|
11
|
+
extras: list[str] | None = None,
|
|
14
12
|
) -> None:
|
|
15
13
|
"""Initialize the error.
|
|
16
14
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from functools import cached_property
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
5
|
|
|
6
6
|
from .exception import StrawberryException
|
|
7
7
|
from .utils.source_finder import SourceFinder
|
|
@@ -32,7 +32,7 @@ class MissingFieldAnnotationError(StrawberryException):
|
|
|
32
32
|
super().__init__(self.message)
|
|
33
33
|
|
|
34
34
|
@cached_property
|
|
35
|
-
def exception_source(self) ->
|
|
35
|
+
def exception_source(self) -> ExceptionSource | None:
|
|
36
36
|
if self.cls is None:
|
|
37
37
|
return None # pragma: no cover
|
|
38
38
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from functools import cached_property
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
5
|
|
|
6
6
|
from .exception import StrawberryException
|
|
7
7
|
from .utils.source_finder import SourceFinder
|
|
@@ -37,7 +37,7 @@ class MissingReturnAnnotationError(StrawberryException):
|
|
|
37
37
|
self.annotation_message = "resolver missing annotation"
|
|
38
38
|
|
|
39
39
|
@cached_property
|
|
40
|
-
def exception_source(self) ->
|
|
40
|
+
def exception_source(self) -> ExceptionSource | None:
|
|
41
41
|
if self.function is None:
|
|
42
42
|
return None # pragma: no cover
|
|
43
43
|
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from enum import Enum
|
|
4
4
|
from functools import cached_property
|
|
5
|
-
from typing import TYPE_CHECKING
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
6
|
|
|
7
7
|
from .exception import StrawberryException
|
|
8
8
|
from .utils.source_finder import SourceFinder
|
|
@@ -56,7 +56,7 @@ class ObjectIsNotClassError(StrawberryException):
|
|
|
56
56
|
return cls(obj, cls.MethodType.TYPE)
|
|
57
57
|
|
|
58
58
|
@cached_property
|
|
59
|
-
def exception_source(self) ->
|
|
59
|
+
def exception_source(self) -> ExceptionSource | None:
|
|
60
60
|
if self.function is None:
|
|
61
61
|
return None # pragma: no cover
|
|
62
62
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from functools import cached_property
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
5
|
|
|
6
6
|
from .exception import StrawberryException
|
|
7
7
|
from .utils.source_finder import SourceFinder
|
|
@@ -31,7 +31,7 @@ class ObjectIsNotAnEnumError(StrawberryException):
|
|
|
31
31
|
super().__init__(self.message)
|
|
32
32
|
|
|
33
33
|
@cached_property
|
|
34
|
-
def exception_source(self) ->
|
|
34
|
+
def exception_source(self) -> ExceptionSource | None:
|
|
35
35
|
if self.cls is None:
|
|
36
36
|
return None # pragma: no cover
|
|
37
37
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from functools import cached_property
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
5
|
|
|
6
6
|
from .exception import StrawberryException
|
|
7
7
|
from .utils.source_finder import SourceFinder
|
|
@@ -32,7 +32,7 @@ class PermissionFailSilentlyRequiresOptionalError(StrawberryException):
|
|
|
32
32
|
super().__init__(self.message)
|
|
33
33
|
|
|
34
34
|
@cached_property
|
|
35
|
-
def exception_source(self) ->
|
|
35
|
+
def exception_source(self) -> ExceptionSource | None:
|
|
36
36
|
origin = self.field.origin
|
|
37
37
|
source_finder = SourceFinder()
|
|
38
38
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from functools import cached_property
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
5
|
|
|
6
6
|
from .exception import StrawberryException
|
|
7
7
|
from .utils.source_finder import SourceFinder
|
|
@@ -32,7 +32,7 @@ class PrivateStrawberryFieldError(StrawberryException):
|
|
|
32
32
|
super().__init__(self.message)
|
|
33
33
|
|
|
34
34
|
@cached_property
|
|
35
|
-
def exception_source(self) ->
|
|
35
|
+
def exception_source(self) -> ExceptionSource | None:
|
|
36
36
|
if self.cls is None:
|
|
37
37
|
return None # pragma: no cover
|
|
38
38
|
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from functools import cached_property
|
|
4
4
|
from pathlib import Path
|
|
5
|
-
from typing import TYPE_CHECKING
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
6
|
|
|
7
7
|
from strawberry.exceptions.utils.source_finder import SourceFinder
|
|
8
8
|
|
|
@@ -45,7 +45,7 @@ class ScalarAlreadyRegisteredError(StrawberryException):
|
|
|
45
45
|
super().__init__(self.message)
|
|
46
46
|
|
|
47
47
|
@cached_property
|
|
48
|
-
def exception_source(self) ->
|
|
48
|
+
def exception_source(self) -> ExceptionSource | None:
|
|
49
49
|
if not all(
|
|
50
50
|
(self.scalar_definition._source_file, self.scalar_definition._source_line)
|
|
51
51
|
):
|
strawberry/exceptions/syntax.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import TYPE_CHECKING
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
4
|
|
|
5
5
|
from pygments.lexers import PythonLexer
|
|
6
6
|
from rich.segment import Segment
|
|
@@ -15,9 +15,9 @@ class Syntax(RichSyntax):
|
|
|
15
15
|
self,
|
|
16
16
|
code: str,
|
|
17
17
|
line_range: tuple[int, int],
|
|
18
|
-
highlight_lines:
|
|
18
|
+
highlight_lines: set[int] | None = None,
|
|
19
19
|
line_offset: int = 0,
|
|
20
|
-
line_annotations:
|
|
20
|
+
line_annotations: dict[int, str] | None = None,
|
|
21
21
|
) -> None:
|
|
22
22
|
self.line_offset = line_offset
|
|
23
23
|
self.line_annotations = line_annotations or {}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from functools import cached_property
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
5
|
|
|
6
6
|
from strawberry.exceptions.utils.source_finder import SourceFinder
|
|
7
7
|
|
|
@@ -40,7 +40,7 @@ class UnresolvedFieldTypeError(StrawberryException):
|
|
|
40
40
|
super().__init__(self.message)
|
|
41
41
|
|
|
42
42
|
@cached_property
|
|
43
|
-
def exception_source(self) ->
|
|
43
|
+
def exception_source(self) -> ExceptionSource | None:
|
|
44
44
|
source_finder = SourceFinder()
|
|
45
45
|
|
|
46
46
|
# field could be attached to the class or not
|
|
@@ -6,12 +6,12 @@ import sys
|
|
|
6
6
|
from dataclasses import dataclass
|
|
7
7
|
from functools import cached_property
|
|
8
8
|
from pathlib import Path
|
|
9
|
-
from typing import TYPE_CHECKING, Any,
|
|
9
|
+
from typing import TYPE_CHECKING, Any, cast
|
|
10
10
|
|
|
11
11
|
from strawberry.exceptions.exception_source import ExceptionSource
|
|
12
12
|
|
|
13
13
|
if TYPE_CHECKING:
|
|
14
|
-
from collections.abc import Sequence
|
|
14
|
+
from collections.abc import Callable, Sequence
|
|
15
15
|
from inspect import Traceback
|
|
16
16
|
|
|
17
17
|
from libcst import BinaryOperation, Call, CSTNode, FunctionDef
|
|
@@ -30,7 +30,7 @@ class LibCSTSourceFinder:
|
|
|
30
30
|
def __init__(self) -> None:
|
|
31
31
|
self.cst = importlib.import_module("libcst")
|
|
32
32
|
|
|
33
|
-
def find_source(self, module: str) ->
|
|
33
|
+
def find_source(self, module: str) -> SourcePath | None:
|
|
34
34
|
# TODO: support for pyodide
|
|
35
35
|
|
|
36
36
|
source_module = sys.modules.get(module)
|
|
@@ -73,11 +73,11 @@ class LibCSTSourceFinder:
|
|
|
73
73
|
|
|
74
74
|
def _find_definition_by_qualname(
|
|
75
75
|
self, qualname: str, nodes: Sequence[CSTNode]
|
|
76
|
-
) ->
|
|
76
|
+
) -> CSTNode | None:
|
|
77
77
|
from libcst import ClassDef, FunctionDef
|
|
78
78
|
|
|
79
79
|
for definition in nodes:
|
|
80
|
-
parent:
|
|
80
|
+
parent: CSTNode | None = definition
|
|
81
81
|
stack = []
|
|
82
82
|
|
|
83
83
|
while parent:
|
|
@@ -101,7 +101,7 @@ class LibCSTSourceFinder:
|
|
|
101
101
|
|
|
102
102
|
def _find_function_definition(
|
|
103
103
|
self, source: SourcePath, function: Callable[..., Any]
|
|
104
|
-
) ->
|
|
104
|
+
) -> FunctionDef | None:
|
|
105
105
|
import libcst.matchers as m
|
|
106
106
|
|
|
107
107
|
matcher = m.FunctionDef(name=m.Name(value=function.__name__))
|
|
@@ -115,7 +115,7 @@ class LibCSTSourceFinder:
|
|
|
115
115
|
|
|
116
116
|
def _find_class_definition(
|
|
117
117
|
self, source: SourcePath, cls: type[Any]
|
|
118
|
-
) ->
|
|
118
|
+
) -> CSTNode | None:
|
|
119
119
|
import libcst.matchers as m
|
|
120
120
|
|
|
121
121
|
matcher = m.ClassDef(name=m.Name(value=cls.__name__))
|
|
@@ -123,7 +123,7 @@ class LibCSTSourceFinder:
|
|
|
123
123
|
class_defs = self._find(source.code, matcher)
|
|
124
124
|
return self._find_definition_by_qualname(cls.__qualname__, class_defs)
|
|
125
125
|
|
|
126
|
-
def find_class(self, cls: type[Any]) ->
|
|
126
|
+
def find_class(self, cls: type[Any]) -> ExceptionSource | None:
|
|
127
127
|
source = self.find_source(cls.__module__)
|
|
128
128
|
|
|
129
129
|
if source is None:
|
|
@@ -149,7 +149,7 @@ class LibCSTSourceFinder:
|
|
|
149
149
|
|
|
150
150
|
def find_class_attribute(
|
|
151
151
|
self, cls: type[Any], attribute_name: str
|
|
152
|
-
) ->
|
|
152
|
+
) -> ExceptionSource | None:
|
|
153
153
|
source = self.find_source(cls.__module__)
|
|
154
154
|
|
|
155
155
|
if source is None:
|
|
@@ -191,7 +191,7 @@ class LibCSTSourceFinder:
|
|
|
191
191
|
error_column_end=attribute_position.end.column,
|
|
192
192
|
)
|
|
193
193
|
|
|
194
|
-
def find_function(self, function: Callable[..., Any]) ->
|
|
194
|
+
def find_function(self, function: Callable[..., Any]) -> ExceptionSource | None:
|
|
195
195
|
source = self.find_source(function.__module__)
|
|
196
196
|
|
|
197
197
|
if source is None:
|
|
@@ -225,7 +225,7 @@ class LibCSTSourceFinder:
|
|
|
225
225
|
|
|
226
226
|
def find_argument(
|
|
227
227
|
self, function: Callable[..., Any], argument_name: str
|
|
228
|
-
) ->
|
|
228
|
+
) -> ExceptionSource | None:
|
|
229
229
|
source = self.find_source(function.__module__)
|
|
230
230
|
|
|
231
231
|
if source is None:
|
|
@@ -263,7 +263,7 @@ class LibCSTSourceFinder:
|
|
|
263
263
|
|
|
264
264
|
def find_union_call(
|
|
265
265
|
self, path: Path, union_name: str, invalid_type: object
|
|
266
|
-
) ->
|
|
266
|
+
) -> ExceptionSource | None:
|
|
267
267
|
import libcst.matchers as m
|
|
268
268
|
|
|
269
269
|
source = path.read_text()
|
|
@@ -339,7 +339,7 @@ class LibCSTSourceFinder:
|
|
|
339
339
|
|
|
340
340
|
def find_union_merge(
|
|
341
341
|
self, union: StrawberryUnion, other: object, frame: Traceback
|
|
342
|
-
) ->
|
|
342
|
+
) -> ExceptionSource | None:
|
|
343
343
|
import libcst.matchers as m
|
|
344
344
|
|
|
345
345
|
path = Path(frame.filename)
|
|
@@ -375,7 +375,7 @@ class LibCSTSourceFinder:
|
|
|
375
375
|
|
|
376
376
|
def find_annotated_union(
|
|
377
377
|
self, union_definition: StrawberryUnion, invalid_type: object
|
|
378
|
-
) ->
|
|
378
|
+
) -> ExceptionSource | None:
|
|
379
379
|
if union_definition._source_file is None:
|
|
380
380
|
return None
|
|
381
381
|
|
|
@@ -503,7 +503,7 @@ class LibCSTSourceFinder:
|
|
|
503
503
|
|
|
504
504
|
def find_scalar_call(
|
|
505
505
|
self, scalar_definition: ScalarDefinition
|
|
506
|
-
) ->
|
|
506
|
+
) -> ExceptionSource | None:
|
|
507
507
|
if scalar_definition._source_file is None:
|
|
508
508
|
return None # pragma: no cover
|
|
509
509
|
|
|
@@ -571,7 +571,7 @@ class LibCSTSourceFinder:
|
|
|
571
571
|
call_node: Any,
|
|
572
572
|
scalar_definition: ScalarDefinition,
|
|
573
573
|
is_newtype: bool,
|
|
574
|
-
) ->
|
|
574
|
+
) -> ExceptionSource | None:
|
|
575
575
|
"""Helper method to create ExceptionSource for scalar calls."""
|
|
576
576
|
import libcst.matchers as m
|
|
577
577
|
|
|
@@ -615,33 +615,33 @@ class LibCSTSourceFinder:
|
|
|
615
615
|
|
|
616
616
|
class SourceFinder:
|
|
617
617
|
@cached_property
|
|
618
|
-
def cst(self) ->
|
|
618
|
+
def cst(self) -> LibCSTSourceFinder | None:
|
|
619
619
|
try:
|
|
620
620
|
return LibCSTSourceFinder()
|
|
621
621
|
except ImportError:
|
|
622
622
|
return None # pragma: no cover
|
|
623
623
|
|
|
624
|
-
def find_class_from_object(self, cls: type[Any]) ->
|
|
624
|
+
def find_class_from_object(self, cls: type[Any]) -> ExceptionSource | None:
|
|
625
625
|
return self.cst.find_class(cls) if self.cst else None
|
|
626
626
|
|
|
627
627
|
def find_class_attribute_from_object(
|
|
628
628
|
self, cls: type[Any], attribute_name: str
|
|
629
|
-
) ->
|
|
629
|
+
) -> ExceptionSource | None:
|
|
630
630
|
return self.cst.find_class_attribute(cls, attribute_name) if self.cst else None
|
|
631
631
|
|
|
632
632
|
def find_function_from_object(
|
|
633
633
|
self, function: Callable[..., Any]
|
|
634
|
-
) ->
|
|
634
|
+
) -> ExceptionSource | None:
|
|
635
635
|
return self.cst.find_function(function) if self.cst else None
|
|
636
636
|
|
|
637
637
|
def find_argument_from_object(
|
|
638
638
|
self, function: Callable[..., Any], argument_name: str
|
|
639
|
-
) ->
|
|
639
|
+
) -> ExceptionSource | None:
|
|
640
640
|
return self.cst.find_argument(function, argument_name) if self.cst else None
|
|
641
641
|
|
|
642
642
|
def find_union_call(
|
|
643
643
|
self, path: Path, union_name: str, invalid_type: object
|
|
644
|
-
) ->
|
|
644
|
+
) -> ExceptionSource | None:
|
|
645
645
|
return (
|
|
646
646
|
self.cst.find_union_call(path, union_name, invalid_type)
|
|
647
647
|
if self.cst
|
|
@@ -650,17 +650,17 @@ class SourceFinder:
|
|
|
650
650
|
|
|
651
651
|
def find_union_merge(
|
|
652
652
|
self, union: StrawberryUnion, other: object, frame: Traceback
|
|
653
|
-
) ->
|
|
653
|
+
) -> ExceptionSource | None:
|
|
654
654
|
return self.cst.find_union_merge(union, other, frame) if self.cst else None
|
|
655
655
|
|
|
656
656
|
def find_scalar_call(
|
|
657
657
|
self, scalar_definition: ScalarDefinition
|
|
658
|
-
) ->
|
|
658
|
+
) -> ExceptionSource | None:
|
|
659
659
|
return self.cst.find_scalar_call(scalar_definition) if self.cst else None
|
|
660
660
|
|
|
661
661
|
def find_annotated_union(
|
|
662
662
|
self, union_definition: StrawberryUnion, invalid_type: object
|
|
663
|
-
) ->
|
|
663
|
+
) -> ExceptionSource | None:
|
|
664
664
|
return (
|
|
665
665
|
self.cst.find_annotated_union(union_definition, invalid_type)
|
|
666
666
|
if self.cst
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import dataclasses
|
|
2
|
+
from collections.abc import Callable
|
|
2
3
|
from dataclasses import dataclass
|
|
3
4
|
from decimal import Decimal
|
|
4
5
|
from functools import cached_property
|
|
5
|
-
from typing import TYPE_CHECKING, Any,
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
6
7
|
from uuid import UUID
|
|
7
8
|
|
|
8
9
|
import pydantic
|
|
@@ -24,12 +25,12 @@ class CompatModelField:
|
|
|
24
25
|
type_: Any
|
|
25
26
|
outer_type_: Any
|
|
26
27
|
default: Any
|
|
27
|
-
default_factory:
|
|
28
|
+
default_factory: Callable[[], Any] | None
|
|
28
29
|
required: bool
|
|
29
|
-
alias:
|
|
30
|
+
alias: str | None
|
|
30
31
|
allow_none: bool
|
|
31
32
|
has_alias: bool
|
|
32
|
-
description:
|
|
33
|
+
description: str | None
|
|
33
34
|
_missing_type: Any
|
|
34
35
|
is_v1: bool
|
|
35
36
|
|
|
@@ -43,8 +44,8 @@ class CompatModelField:
|
|
|
43
44
|
|
|
44
45
|
|
|
45
46
|
ATTR_TO_TYPE_MAP = {
|
|
46
|
-
"NoneStr": Optional[str],
|
|
47
|
-
"NoneBytes": Optional[bytes],
|
|
47
|
+
"NoneStr": Optional[str], # noqa: UP045
|
|
48
|
+
"NoneBytes": Optional[bytes], # noqa: UP045
|
|
48
49
|
"StrBytes": None,
|
|
49
50
|
"NoneStrBytes": None,
|
|
50
51
|
"StrictStr": str,
|
|
@@ -296,7 +297,7 @@ class PydanticCompat:
|
|
|
296
297
|
|
|
297
298
|
|
|
298
299
|
if IS_PYDANTIC_V2:
|
|
299
|
-
from
|
|
300
|
+
from typing import get_args, get_origin
|
|
300
301
|
|
|
301
302
|
from pydantic.v1.typing import is_new_type
|
|
302
303
|
from pydantic.v1.utils import lenient_issubclass, smart_deepcopy
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import copy
|
|
4
4
|
import dataclasses
|
|
5
|
-
from typing import TYPE_CHECKING, Any,
|
|
5
|
+
from typing import TYPE_CHECKING, Any, cast
|
|
6
6
|
|
|
7
7
|
from strawberry.types.base import (
|
|
8
8
|
StrawberryList,
|
|
@@ -18,7 +18,7 @@ if TYPE_CHECKING:
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
def _convert_from_pydantic_to_strawberry_type(
|
|
21
|
-
type_:
|
|
21
|
+
type_: StrawberryType | type,
|
|
22
22
|
data_from_model=None, # noqa: ANN001
|
|
23
23
|
extra=None, # noqa: ANN001
|
|
24
24
|
) -> Any:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import TYPE_CHECKING, Any,
|
|
3
|
+
from typing import TYPE_CHECKING, Any, TypeVar
|
|
4
4
|
from typing_extensions import Protocol
|
|
5
5
|
|
|
6
6
|
from pydantic import BaseModel
|
|
@@ -22,7 +22,7 @@ class StrawberryTypeFromPydantic(Protocol[PydanticModel]):
|
|
|
22
22
|
|
|
23
23
|
@staticmethod
|
|
24
24
|
def from_pydantic(
|
|
25
|
-
instance: PydanticModel, extra:
|
|
25
|
+
instance: PydanticModel, extra: dict[str, Any] | None = None
|
|
26
26
|
) -> StrawberryTypeFromPydantic[PydanticModel]: ...
|
|
27
27
|
|
|
28
28
|
def to_pydantic(self, **kwargs: Any) -> PydanticModel: ...
|
|
@@ -5,9 +5,7 @@ import warnings
|
|
|
5
5
|
from typing import (
|
|
6
6
|
TYPE_CHECKING,
|
|
7
7
|
Any,
|
|
8
|
-
Callable,
|
|
9
8
|
Optional,
|
|
10
|
-
Union,
|
|
11
9
|
cast,
|
|
12
10
|
)
|
|
13
11
|
|
|
@@ -31,18 +29,18 @@ from strawberry.utils.typing import get_list_annotation, is_list
|
|
|
31
29
|
from .exceptions import MissingFieldsListError
|
|
32
30
|
|
|
33
31
|
if TYPE_CHECKING:
|
|
34
|
-
from collections.abc import Sequence
|
|
32
|
+
from collections.abc import Callable, Sequence
|
|
35
33
|
|
|
36
34
|
from strawberry.types.base import WithStrawberryObjectDefinition
|
|
37
35
|
|
|
38
36
|
|
|
39
|
-
def get_type_for_field(field: CompatModelField) ->
|
|
37
|
+
def get_type_for_field(field: CompatModelField) -> type[None | list] | Any:
|
|
40
38
|
type_ = field.outer_type_
|
|
41
39
|
type_ = normalize_type(type_)
|
|
42
40
|
return field_type_to_type(type_)
|
|
43
41
|
|
|
44
42
|
|
|
45
|
-
def field_type_to_type(type_: type) ->
|
|
43
|
+
def field_type_to_type(type_: type) -> Any | list[Any] | None:
|
|
46
44
|
error_class: Any = str
|
|
47
45
|
strawberry_type: Any = error_class
|
|
48
46
|
|
|
@@ -56,21 +54,21 @@ def field_type_to_type(type_: type) -> Union[Any, list[Any], None]:
|
|
|
56
54
|
else:
|
|
57
55
|
strawberry_type = list[error_class]
|
|
58
56
|
|
|
59
|
-
strawberry_type = Optional[strawberry_type]
|
|
57
|
+
strawberry_type = Optional[strawberry_type] # noqa: UP045
|
|
60
58
|
elif lenient_issubclass(type_, BaseModel):
|
|
61
59
|
strawberry_type = get_strawberry_type_from_model(type_)
|
|
62
|
-
return Optional[strawberry_type]
|
|
60
|
+
return Optional[strawberry_type] # noqa: UP045
|
|
63
61
|
|
|
64
|
-
return Optional[list[strawberry_type]]
|
|
62
|
+
return Optional[list[strawberry_type]] # noqa: UP045
|
|
65
63
|
|
|
66
64
|
|
|
67
65
|
def error_type(
|
|
68
66
|
model: type[BaseModel],
|
|
69
67
|
*,
|
|
70
|
-
fields:
|
|
71
|
-
name:
|
|
72
|
-
description:
|
|
73
|
-
directives:
|
|
68
|
+
fields: list[str] | None = None,
|
|
69
|
+
name: str | None = None,
|
|
70
|
+
description: str | None = None,
|
|
71
|
+
directives: Sequence[object] | None = (),
|
|
74
72
|
all_fields: bool = False,
|
|
75
73
|
) -> Callable[..., type]:
|
|
76
74
|
def wrap(cls: type) -> type:
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import builtins
|
|
2
|
-
from
|
|
2
|
+
from types import UnionType
|
|
3
|
+
from typing import (
|
|
4
|
+
Annotated,
|
|
5
|
+
Any,
|
|
6
|
+
Union,
|
|
7
|
+
)
|
|
8
|
+
from typing import GenericAlias as TypingGenericAlias # type: ignore
|
|
3
9
|
|
|
4
10
|
from pydantic import BaseModel
|
|
5
11
|
|
|
@@ -14,18 +20,6 @@ from strawberry.experimental.pydantic.exceptions import (
|
|
|
14
20
|
)
|
|
15
21
|
from strawberry.types.base import StrawberryObjectDefinition
|
|
16
22
|
|
|
17
|
-
try:
|
|
18
|
-
from types import UnionType as TypingUnionType
|
|
19
|
-
except ImportError:
|
|
20
|
-
import sys
|
|
21
|
-
|
|
22
|
-
if sys.version_info < (3, 10):
|
|
23
|
-
TypingUnionType = ()
|
|
24
|
-
else:
|
|
25
|
-
raise
|
|
26
|
-
|
|
27
|
-
from typing import GenericAlias as TypingGenericAlias # type: ignore
|
|
28
|
-
|
|
29
23
|
|
|
30
24
|
def replace_pydantic_types(type_: Any, is_input: bool) -> Any:
|
|
31
25
|
if lenient_issubclass(type_, BaseModel):
|
|
@@ -55,8 +49,8 @@ def replace_types_recursively(
|
|
|
55
49
|
|
|
56
50
|
if isinstance(replaced_type, TypingGenericAlias):
|
|
57
51
|
return TypingGenericAlias(origin, converted)
|
|
58
|
-
if isinstance(replaced_type,
|
|
59
|
-
return Union[converted]
|
|
52
|
+
if isinstance(replaced_type, UnionType):
|
|
53
|
+
return Union[converted] # noqa: UP007
|
|
60
54
|
|
|
61
55
|
# TODO: investigate if we could move the check for annotated to the top
|
|
62
56
|
if origin is Annotated and converted:
|