strawberry-graphql 0.235.1.dev1719337273__py3-none-any.whl → 0.236.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- strawberry/__init__.py +17 -11
- strawberry/aiohttp/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/aiohttp/handlers/graphql_ws_handler.py +3 -0
- strawberry/aiohttp/test/client.py +3 -0
- strawberry/aiohttp/views.py +3 -0
- strawberry/annotation.py +19 -22
- strawberry/asgi/__init__.py +3 -3
- strawberry/asgi/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/asgi/handlers/graphql_ws_handler.py +3 -0
- strawberry/asgi/test/client.py +3 -0
- strawberry/chalice/views.py +12 -3
- strawberry/channels/handlers/__init__.py +0 -0
- strawberry/channels/handlers/base.py +5 -5
- strawberry/channels/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/channels/handlers/graphql_ws_handler.py +3 -0
- strawberry/channels/handlers/http_handler.py +5 -2
- strawberry/channels/handlers/ws_handler.py +4 -1
- strawberry/channels/router.py +9 -5
- strawberry/channels/testing.py +11 -4
- strawberry/cli/commands/upgrade/__init__.py +13 -5
- strawberry/cli/commands/upgrade/_fake_progress.py +2 -1
- strawberry/cli/commands/upgrade/_run_codemod.py +18 -1
- strawberry/codegen/exceptions.py +8 -0
- strawberry/codegen/query_codegen.py +16 -7
- strawberry/codegen/types.py +32 -1
- strawberry/codemods/update_imports.py +136 -0
- strawberry/dataloader.py +13 -0
- strawberry/directive.py +52 -4
- strawberry/django/context.py +4 -1
- strawberry/django/test/client.py +3 -0
- strawberry/django/views.py +3 -0
- strawberry/exceptions/__init__.py +5 -5
- strawberry/exceptions/duplicated_type_name.py +1 -1
- strawberry/exceptions/invalid_argument_type.py +3 -3
- strawberry/exceptions/invalid_union_type.py +5 -6
- strawberry/exceptions/missing_arguments_annotations.py +1 -1
- strawberry/exceptions/missing_dependencies.py +10 -2
- strawberry/exceptions/missing_return_annotation.py +1 -1
- strawberry/exceptions/permission_fail_silently_requires_optional.py +3 -3
- strawberry/exceptions/scalar_already_registered.py +1 -1
- strawberry/exceptions/unresolved_field_type.py +2 -2
- strawberry/exceptions/utils/source_finder.py +5 -2
- strawberry/experimental/pydantic/conversion.py +5 -5
- strawberry/experimental/pydantic/conversion_types.py +4 -2
- strawberry/experimental/pydantic/error_type.py +2 -2
- strawberry/experimental/pydantic/fields.py +2 -2
- strawberry/experimental/pydantic/object_type.py +11 -7
- strawberry/experimental/pydantic/utils.py +4 -5
- strawberry/ext/dataclasses/dataclasses.py +2 -1
- strawberry/ext/mypy_plugin.py +10 -8
- strawberry/extensions/add_validation_rules.py +27 -23
- strawberry/extensions/base_extension.py +6 -4
- strawberry/extensions/directives.py +4 -1
- strawberry/extensions/disable_validation.py +15 -12
- strawberry/extensions/field_extension.py +11 -5
- strawberry/extensions/mask_errors.py +3 -0
- strawberry/extensions/max_aliases.py +21 -19
- strawberry/extensions/max_tokens.py +14 -16
- strawberry/extensions/parser_cache.py +22 -19
- strawberry/extensions/pyinstrument.py +4 -8
- strawberry/extensions/query_depth_limiter.py +22 -23
- strawberry/extensions/runner.py +3 -0
- strawberry/extensions/tracing/apollo.py +3 -0
- strawberry/extensions/tracing/datadog.py +7 -2
- strawberry/extensions/tracing/opentelemetry.py +3 -0
- strawberry/extensions/tracing/sentry.py +3 -0
- strawberry/extensions/tracing/utils.py +3 -0
- strawberry/extensions/utils.py +3 -0
- strawberry/extensions/validation_cache.py +23 -20
- strawberry/fastapi/context.py +3 -0
- strawberry/fastapi/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/fastapi/handlers/graphql_ws_handler.py +3 -0
- strawberry/fastapi/router.py +3 -0
- strawberry/federation/argument.py +4 -1
- strawberry/federation/enum.py +5 -3
- strawberry/federation/field.py +6 -3
- strawberry/federation/mutation.py +2 -0
- strawberry/federation/object_type.py +7 -4
- strawberry/federation/scalar.py +43 -20
- strawberry/federation/schema.py +12 -9
- strawberry/federation/schema_directive.py +2 -2
- strawberry/federation/schema_directives.py +19 -1
- strawberry/federation/types.py +5 -2
- strawberry/federation/union.py +27 -8
- strawberry/field_extensions/input_mutation.py +5 -2
- strawberry/file_uploads/scalars.py +3 -1
- strawberry/file_uploads/utils.py +3 -0
- strawberry/flask/views.py +8 -2
- strawberry/http/__init__.py +9 -0
- strawberry/http/async_base_view.py +4 -3
- strawberry/http/base.py +5 -7
- strawberry/http/exceptions.py +3 -0
- strawberry/http/ides.py +3 -0
- strawberry/http/sync_base_view.py +4 -3
- strawberry/http/temporal_response.py +3 -0
- strawberry/http/types.py +5 -2
- strawberry/http/typevars.py +3 -0
- strawberry/litestar/controller.py +6 -0
- strawberry/litestar/handlers/__init__.py +0 -0
- strawberry/litestar/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/litestar/handlers/graphql_ws_handler.py +3 -0
- strawberry/parent.py +27 -21
- strawberry/permission.py +70 -27
- strawberry/printer/ast_from_value.py +4 -1
- strawberry/printer/printer.py +8 -5
- strawberry/quart/views.py +3 -0
- strawberry/relay/exceptions.py +7 -0
- strawberry/relay/fields.py +70 -45
- strawberry/relay/types.py +78 -78
- strawberry/relay/utils.py +10 -1
- strawberry/resolvers.py +3 -0
- strawberry/sanic/context.py +3 -0
- strawberry/sanic/utils.py +10 -8
- strawberry/sanic/views.py +5 -9
- strawberry/scalars.py +6 -2
- strawberry/schema/base.py +7 -4
- strawberry/schema/compat.py +12 -2
- strawberry/schema/config.py +3 -0
- strawberry/schema/exceptions.py +3 -0
- strawberry/schema/execute.py +3 -0
- strawberry/schema/name_converter.py +12 -9
- strawberry/schema/schema.py +46 -9
- strawberry/schema/schema_converter.py +16 -14
- strawberry/schema/types/base_scalars.py +3 -1
- strawberry/schema/types/concrete_type.py +4 -4
- strawberry/schema/types/scalar.py +8 -1
- strawberry/schema/validation_rules/one_of.py +3 -0
- strawberry/schema_codegen/__init__.py +3 -0
- strawberry/schema_directive.py +2 -2
- strawberry/starlite/controller.py +3 -0
- strawberry/starlite/handlers/__init__.py +0 -0
- strawberry/starlite/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/starlite/handlers/graphql_ws_handler.py +3 -0
- strawberry/subscriptions/__init__.py +6 -0
- strawberry/subscriptions/protocols/graphql_transport_ws/__init__.py +5 -0
- strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py +12 -17
- strawberry/subscriptions/protocols/graphql_transport_ws/types.py +21 -25
- strawberry/subscriptions/protocols/graphql_ws/__init__.py +14 -0
- strawberry/subscriptions/protocols/graphql_ws/handlers.py +8 -5
- strawberry/subscriptions/protocols/graphql_ws/types.py +11 -0
- strawberry/test/client.py +44 -29
- strawberry/tools/create_type.py +27 -8
- strawberry/tools/merge_types.py +5 -3
- strawberry/types/__init__.py +8 -1
- strawberry/{arguments.py → types/arguments.py} +44 -13
- strawberry/{auto.py → types/auto.py} +21 -3
- strawberry/types/{types.py → base.py} +234 -10
- strawberry/{enum.py → types/enum.py} +69 -9
- strawberry/types/execution.py +3 -0
- strawberry/{field.py → types/field.py} +46 -23
- strawberry/types/fields/resolver.py +2 -2
- strawberry/types/graphql.py +3 -0
- strawberry/types/info.py +50 -7
- strawberry/{lazy_type.py → types/lazy_type.py} +50 -0
- strawberry/types/mutation.py +351 -0
- strawberry/types/nodes.py +4 -2
- strawberry/{object_type.py → types/object_type.py} +108 -29
- strawberry/{private.py → types/private.py} +13 -6
- strawberry/{custom_scalar.py → types/scalar.py} +39 -23
- strawberry/types/type_resolver.py +21 -16
- strawberry/{union.py → types/union.py} +24 -9
- strawberry/{unset.py → types/unset.py} +20 -0
- strawberry/utils/aio.py +8 -0
- strawberry/utils/await_maybe.py +3 -0
- strawberry/utils/dataclasses.py +3 -0
- strawberry/utils/debug.py +5 -2
- strawberry/utils/deprecations.py +3 -0
- strawberry/utils/graphql_lexer.py +3 -0
- strawberry/utils/importer.py +3 -0
- strawberry/utils/inspect.py +39 -30
- strawberry/utils/logging.py +3 -0
- strawberry/utils/operation.py +3 -0
- strawberry/utils/str_converters.py +3 -0
- strawberry/utils/typing.py +33 -16
- {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/METADATA +1 -1
- strawberry_graphql-0.236.0.dist-info/RECORD +255 -0
- strawberry/mutation.py +0 -8
- strawberry/type.py +0 -232
- strawberry_graphql-0.235.1.dev1719337273.dist-info/RECORD +0 -252
- {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/LICENSE +0 -0
- {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/WHEEL +0 -0
- {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,136 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import libcst as cst
|
4
|
+
import libcst.matchers as m
|
5
|
+
from libcst.codemod import CodemodContext, VisitorBasedCodemodCommand
|
6
|
+
from libcst.codemod.visitors import AddImportsVisitor, RemoveImportsVisitor
|
7
|
+
|
8
|
+
|
9
|
+
class UpdateImportsCodemod(VisitorBasedCodemodCommand):
|
10
|
+
def __init__(self, context: CodemodContext) -> None:
|
11
|
+
super().__init__(context)
|
12
|
+
self.add_imports_visitor = AddImportsVisitor(context)
|
13
|
+
self.remove_imports_visitor = RemoveImportsVisitor(context)
|
14
|
+
|
15
|
+
def _update_imports(
|
16
|
+
self, node: cst.ImportFrom, updated_node: cst.ImportFrom
|
17
|
+
) -> cst.ImportFrom:
|
18
|
+
imports = [
|
19
|
+
"field",
|
20
|
+
"union",
|
21
|
+
"auto",
|
22
|
+
"unset",
|
23
|
+
"arguments",
|
24
|
+
"lazy_type",
|
25
|
+
"object_type",
|
26
|
+
"private",
|
27
|
+
"enum",
|
28
|
+
]
|
29
|
+
|
30
|
+
for import_name in imports:
|
31
|
+
if m.matches(
|
32
|
+
node,
|
33
|
+
m.ImportFrom(
|
34
|
+
module=m.Attribute(
|
35
|
+
value=m.Name("strawberry"), attr=m.Name(import_name)
|
36
|
+
)
|
37
|
+
),
|
38
|
+
):
|
39
|
+
updated_node = updated_node.with_changes(
|
40
|
+
module=cst.Attribute(
|
41
|
+
value=cst.Attribute(
|
42
|
+
value=cst.Name("strawberry"), attr=cst.Name("types")
|
43
|
+
),
|
44
|
+
attr=cst.Name(import_name),
|
45
|
+
),
|
46
|
+
)
|
47
|
+
|
48
|
+
return updated_node
|
49
|
+
|
50
|
+
def _update_types_types_imports(
|
51
|
+
self, node: cst.ImportFrom, updated_node: cst.ImportFrom
|
52
|
+
) -> cst.ImportFrom:
|
53
|
+
if m.matches(
|
54
|
+
node,
|
55
|
+
m.ImportFrom(
|
56
|
+
module=m.Attribute(
|
57
|
+
value=m.Attribute(value=m.Name("strawberry"), attr=m.Name("types")),
|
58
|
+
attr=m.Name("types"),
|
59
|
+
)
|
60
|
+
),
|
61
|
+
):
|
62
|
+
updated_node = updated_node.with_changes(
|
63
|
+
module=cst.Attribute(
|
64
|
+
value=cst.Attribute(
|
65
|
+
value=cst.Name("strawberry"), attr=cst.Name("types")
|
66
|
+
),
|
67
|
+
attr=cst.Name("base"),
|
68
|
+
),
|
69
|
+
)
|
70
|
+
|
71
|
+
return updated_node
|
72
|
+
|
73
|
+
def _update_strawberry_type_imports(
|
74
|
+
self, node: cst.ImportFrom, updated_node: cst.ImportFrom
|
75
|
+
) -> cst.ImportFrom:
|
76
|
+
if m.matches(
|
77
|
+
node,
|
78
|
+
m.ImportFrom(
|
79
|
+
module=m.Attribute(value=m.Name("strawberry"), attr=m.Name("type"))
|
80
|
+
),
|
81
|
+
):
|
82
|
+
has_get_object_definition = (
|
83
|
+
any(
|
84
|
+
m.matches(name, m.ImportAlias(name=m.Name("get_object_definition")))
|
85
|
+
for name in node.names
|
86
|
+
)
|
87
|
+
if not isinstance(node.names, cst.ImportStar)
|
88
|
+
else False
|
89
|
+
)
|
90
|
+
|
91
|
+
has_has_object_definition = (
|
92
|
+
any(
|
93
|
+
m.matches(name, m.ImportAlias(name=m.Name("has_object_definition")))
|
94
|
+
for name in node.names
|
95
|
+
)
|
96
|
+
if not isinstance(node.names, cst.ImportStar)
|
97
|
+
else False
|
98
|
+
)
|
99
|
+
|
100
|
+
updated_node = updated_node.with_changes(
|
101
|
+
module=cst.Attribute(
|
102
|
+
value=cst.Attribute(
|
103
|
+
value=cst.Name("strawberry"), attr=cst.Name("types")
|
104
|
+
),
|
105
|
+
attr=cst.Name("base"),
|
106
|
+
),
|
107
|
+
)
|
108
|
+
|
109
|
+
self.remove_imports_visitor.remove_unused_import(
|
110
|
+
self.context, "strawberry.types.base", "get_object_definition"
|
111
|
+
)
|
112
|
+
|
113
|
+
self.remove_imports_visitor.remove_unused_import(
|
114
|
+
self.context, "strawberry.types.base", "has_object_definition"
|
115
|
+
)
|
116
|
+
|
117
|
+
if has_get_object_definition:
|
118
|
+
self.add_imports_visitor.add_needed_import(
|
119
|
+
self.context, "strawberry.types", "get_object_definition"
|
120
|
+
)
|
121
|
+
|
122
|
+
if has_has_object_definition:
|
123
|
+
self.add_imports_visitor.add_needed_import(
|
124
|
+
self.context, "strawberry.types", "has_object_definition"
|
125
|
+
)
|
126
|
+
|
127
|
+
return updated_node
|
128
|
+
|
129
|
+
def leave_ImportFrom(
|
130
|
+
self, node: cst.ImportFrom, updated_node: cst.ImportFrom
|
131
|
+
) -> cst.ImportFrom:
|
132
|
+
updated_node = self._update_imports(updated_node, updated_node)
|
133
|
+
updated_node = self._update_types_types_imports(updated_node, updated_node)
|
134
|
+
updated_node = self._update_strawberry_type_imports(updated_node, updated_node)
|
135
|
+
|
136
|
+
return updated_node
|
strawberry/dataloader.py
CHANGED
@@ -267,3 +267,16 @@ async def dispatch_batch(loader: DataLoader, batch: Batch) -> None:
|
|
267
267
|
except Exception as e:
|
268
268
|
for task in batch.tasks:
|
269
269
|
task.future.set_exception(e)
|
270
|
+
|
271
|
+
|
272
|
+
__all__ = [
|
273
|
+
"DataLoader",
|
274
|
+
"Batch",
|
275
|
+
"LoaderTask",
|
276
|
+
"AbstractCache",
|
277
|
+
"DefaultCache",
|
278
|
+
"should_create_new_batch",
|
279
|
+
"get_current_batch",
|
280
|
+
"dispatch",
|
281
|
+
"dispatch_batch",
|
282
|
+
]
|
strawberry/directive.py
CHANGED
@@ -7,21 +7,45 @@ from typing_extensions import Annotated
|
|
7
7
|
|
8
8
|
from graphql import DirectiveLocation
|
9
9
|
|
10
|
-
from strawberry.field import StrawberryField
|
10
|
+
from strawberry.types.field import StrawberryField
|
11
11
|
from strawberry.types.fields.resolver import (
|
12
12
|
INFO_PARAMSPEC,
|
13
13
|
ReservedType,
|
14
14
|
StrawberryResolver,
|
15
15
|
)
|
16
|
-
from strawberry.unset import UNSET
|
16
|
+
from strawberry.types.unset import UNSET
|
17
17
|
|
18
18
|
if TYPE_CHECKING:
|
19
19
|
import inspect
|
20
20
|
|
21
|
-
from strawberry.arguments import StrawberryArgument
|
21
|
+
from strawberry.types.arguments import StrawberryArgument
|
22
22
|
|
23
23
|
|
24
|
-
|
24
|
+
# TODO: should this be directive argument?
|
25
|
+
def directive_field(
|
26
|
+
name: str,
|
27
|
+
default: object = UNSET,
|
28
|
+
) -> Any:
|
29
|
+
"""Function to add metadata to a directive argument, like the GraphQL name.
|
30
|
+
|
31
|
+
Args:
|
32
|
+
name: The GraphQL name of the directive argument
|
33
|
+
default: The default value of the argument
|
34
|
+
|
35
|
+
Returns:
|
36
|
+
A StrawberryField object that can be used to customise a directive argument
|
37
|
+
|
38
|
+
Example:
|
39
|
+
```python
|
40
|
+
import strawberry
|
41
|
+
from strawberry.schema_directive import Location
|
42
|
+
|
43
|
+
|
44
|
+
@strawberry.schema_directive(locations=[Location.FIELD_DEFINITION])
|
45
|
+
class Sensitive:
|
46
|
+
reason: str = strawberry.directive_field(name="as")
|
47
|
+
```
|
48
|
+
"""
|
25
49
|
return StrawberryField(
|
26
50
|
python_name=None,
|
27
51
|
graphql_name=name,
|
@@ -74,6 +98,30 @@ def directive(
|
|
74
98
|
description: Optional[str] = None,
|
75
99
|
name: Optional[str] = None,
|
76
100
|
) -> Callable[[Callable[..., T]], StrawberryDirective[T]]:
|
101
|
+
"""Decorator to create a GraphQL operation directive.
|
102
|
+
|
103
|
+
Args:
|
104
|
+
locations: The locations where the directive can be used
|
105
|
+
description: The GraphQL description of the directive
|
106
|
+
name: The GraphQL name of the directive
|
107
|
+
|
108
|
+
Returns:
|
109
|
+
A StrawberryDirective object that can be used to customise a directive
|
110
|
+
|
111
|
+
Example:
|
112
|
+
```python
|
113
|
+
import strawberry
|
114
|
+
from strawberry.directive import DirectiveLocation
|
115
|
+
|
116
|
+
|
117
|
+
@strawberry.directive(
|
118
|
+
locations=[DirectiveLocation.FIELD], description="Make string uppercase"
|
119
|
+
)
|
120
|
+
def turn_uppercase(value: str):
|
121
|
+
return value.upper()
|
122
|
+
```
|
123
|
+
"""
|
124
|
+
|
77
125
|
def _wrap(f: Callable[..., T]) -> StrawberryDirective[T]:
|
78
126
|
return StrawberryDirective(
|
79
127
|
python_name=f.__name__,
|
strawberry/django/context.py
CHANGED
@@ -18,5 +18,8 @@ class StrawberryDjangoContext:
|
|
18
18
|
return super().__getattribute__(key)
|
19
19
|
|
20
20
|
def get(self, key: str) -> Any:
|
21
|
-
"""Enable .get notation for accessing the request"""
|
21
|
+
"""Enable .get notation for accessing the request."""
|
22
22
|
return super().__getattribute__(key)
|
23
|
+
|
24
|
+
|
25
|
+
__all__ = ["StrawberryDjangoContext"]
|
strawberry/django/test/client.py
CHANGED
strawberry/django/views.py
CHANGED
@@ -25,7 +25,7 @@ from .unresolved_field_type import UnresolvedFieldTypeError
|
|
25
25
|
if TYPE_CHECKING:
|
26
26
|
from graphql import GraphQLInputObjectType, GraphQLObjectType
|
27
27
|
|
28
|
-
from strawberry.
|
28
|
+
from strawberry.types.base import StrawberryType
|
29
29
|
|
30
30
|
from .exception_source import ExceptionSource
|
31
31
|
|
@@ -34,7 +34,7 @@ setup_exception_handler()
|
|
34
34
|
|
35
35
|
# TODO: this doesn't seem to be tested
|
36
36
|
class WrongReturnTypeForUnion(Exception):
|
37
|
-
"""The Union type cannot be resolved because it's not a field"""
|
37
|
+
"""The Union type cannot be resolved because it's not a field."""
|
38
38
|
|
39
39
|
def __init__(self, field_name: str, result_type: str) -> None:
|
40
40
|
message = (
|
@@ -46,7 +46,7 @@ class WrongReturnTypeForUnion(Exception):
|
|
46
46
|
|
47
47
|
|
48
48
|
class UnallowedReturnTypeForUnion(Exception):
|
49
|
-
"""The return type is not in the list of Union types"""
|
49
|
+
"""The return type is not in the list of Union types."""
|
50
50
|
|
51
51
|
def __init__(
|
52
52
|
self, field_name: str, result_type: str, allowed_types: Set[GraphQLObjectType]
|
@@ -144,7 +144,7 @@ class InvalidDefaultFactoryError(Exception):
|
|
144
144
|
|
145
145
|
|
146
146
|
class InvalidCustomContext(Exception):
|
147
|
-
"""Raised when a custom context object is of the wrong python type"""
|
147
|
+
"""Raised when a custom context object is of the wrong python type."""
|
148
148
|
|
149
149
|
def __init__(self) -> None:
|
150
150
|
message = (
|
@@ -155,7 +155,7 @@ class InvalidCustomContext(Exception):
|
|
155
155
|
|
156
156
|
|
157
157
|
class StrawberryGraphQLError(GraphQLError):
|
158
|
-
"""Use it when you want to override the graphql.GraphQLError in custom extensions"""
|
158
|
+
"""Use it when you want to override the graphql.GraphQLError in custom extensions."""
|
159
159
|
|
160
160
|
|
161
161
|
__all__ = [
|
@@ -13,7 +13,7 @@ if TYPE_CHECKING:
|
|
13
13
|
|
14
14
|
|
15
15
|
class DuplicatedTypeName(StrawberryException):
|
16
|
-
"""Raised when the same type with different definition is reused inside a schema"""
|
16
|
+
"""Raised when the same type with different definition is reused inside a schema."""
|
17
17
|
|
18
18
|
def __init__(
|
19
19
|
self,
|
@@ -3,13 +3,13 @@ from __future__ import annotations
|
|
3
3
|
from functools import cached_property
|
4
4
|
from typing import TYPE_CHECKING, Optional
|
5
5
|
|
6
|
-
from strawberry.
|
6
|
+
from strawberry.types.base import get_object_definition
|
7
7
|
|
8
8
|
from .exception import StrawberryException
|
9
9
|
from .utils.source_finder import SourceFinder
|
10
10
|
|
11
11
|
if TYPE_CHECKING:
|
12
|
-
from strawberry.arguments import StrawberryArgument
|
12
|
+
from strawberry.types.arguments import StrawberryArgument
|
13
13
|
from strawberry.types.fields.resolver import StrawberryResolver
|
14
14
|
|
15
15
|
from .exception_source import ExceptionSource
|
@@ -21,7 +21,7 @@ class InvalidArgumentTypeError(StrawberryException):
|
|
21
21
|
resolver: StrawberryResolver,
|
22
22
|
argument: StrawberryArgument,
|
23
23
|
) -> None:
|
24
|
-
from strawberry.union import StrawberryUnion
|
24
|
+
from strawberry.types.union import StrawberryUnion
|
25
25
|
|
26
26
|
self.function = resolver.wrapped_func
|
27
27
|
self.argument_name = argument.python_name
|
@@ -10,13 +10,13 @@ from strawberry.exceptions.utils.source_finder import SourceFinder
|
|
10
10
|
from .exception import StrawberryException
|
11
11
|
|
12
12
|
if TYPE_CHECKING:
|
13
|
-
from strawberry.union import StrawberryUnion
|
13
|
+
from strawberry.types.union import StrawberryUnion
|
14
14
|
|
15
15
|
from .exception_source import ExceptionSource
|
16
16
|
|
17
17
|
|
18
18
|
class InvalidUnionTypeError(StrawberryException):
|
19
|
-
"""The union is constructed with an invalid type"""
|
19
|
+
"""The union is constructed with an invalid type."""
|
20
20
|
|
21
21
|
invalid_type: object
|
22
22
|
|
@@ -26,8 +26,8 @@ class InvalidUnionTypeError(StrawberryException):
|
|
26
26
|
invalid_type: object,
|
27
27
|
union_definition: Optional[StrawberryUnion] = None,
|
28
28
|
) -> None:
|
29
|
-
from strawberry.
|
30
|
-
from strawberry.
|
29
|
+
from strawberry.types.base import StrawberryList
|
30
|
+
from strawberry.types.scalar import ScalarWrapper
|
31
31
|
|
32
32
|
self.union_name = union_name
|
33
33
|
self.invalid_type = invalid_type
|
@@ -78,8 +78,7 @@ class InvalidUnionTypeError(StrawberryException):
|
|
78
78
|
|
79
79
|
|
80
80
|
class InvalidTypeForUnionMergeError(StrawberryException):
|
81
|
-
"""A specialized version of InvalidUnionTypeError for when trying
|
82
|
-
to merge unions using the pipe operator."""
|
81
|
+
"""A specialized version of InvalidUnionTypeError for when trying to merge unions using the pipe operator."""
|
83
82
|
|
84
83
|
invalid_type: Type
|
85
84
|
|
@@ -4,8 +4,7 @@ from typing import Optional
|
|
4
4
|
|
5
5
|
|
6
6
|
class MissingOptionalDependenciesError(Exception):
|
7
|
-
"""Some optional dependencies that are required for a particular
|
8
|
-
task are missing."""
|
7
|
+
"""Some optional dependencies that are required for a particular task are missing."""
|
9
8
|
|
10
9
|
def __init__(
|
11
10
|
self,
|
@@ -13,8 +12,17 @@ class MissingOptionalDependenciesError(Exception):
|
|
13
12
|
packages: Optional[list[str]] = None,
|
14
13
|
extras: Optional[list[str]] = None,
|
15
14
|
) -> None:
|
15
|
+
"""Initialize the error.
|
16
|
+
|
17
|
+
Args:
|
18
|
+
packages: List of packages that are required but missing.
|
19
|
+
extras: List of extras that are required but missing.
|
20
|
+
"""
|
16
21
|
packages = packages or []
|
22
|
+
|
17
23
|
if extras:
|
18
24
|
packages.append(f"'strawberry-graphql[{','.join(extras)}]'")
|
25
|
+
|
19
26
|
hint = f" (hint: pip install {' '.join(packages)})" if packages else ""
|
27
|
+
|
20
28
|
self.message = f"Some optional dependencies are missing{hint}"
|
@@ -20,7 +20,7 @@ class PermissionFailSilentlyRequiresOptionalError(StrawberryException):
|
|
20
20
|
self.rich_message = (
|
21
21
|
"fail_silently permissions can only be used with fields of type "
|
22
22
|
f"optional or list. Provided field `[underline]{field.name}[/]` "
|
23
|
-
f"is of type `[underline]{field.type.__name__}[/]`"
|
23
|
+
f"is of type `[underline]{field.type.__name__}[/]`"
|
24
24
|
)
|
25
25
|
self.annotation_message = "field defined here"
|
26
26
|
self.suggestion = (
|
@@ -38,14 +38,14 @@ class PermissionFailSilentlyRequiresOptionalError(StrawberryException):
|
|
38
38
|
source = None
|
39
39
|
if origin is not None:
|
40
40
|
source = source_finder.find_class_attribute_from_object(
|
41
|
-
origin,
|
41
|
+
origin,
|
42
42
|
self.field.python_name,
|
43
43
|
)
|
44
44
|
|
45
45
|
# in case it is a function
|
46
46
|
if source is None and self.field.base_resolver is not None:
|
47
47
|
source = source_finder.find_function_from_object(
|
48
|
-
self.field.base_resolver.wrapped_func
|
48
|
+
self.field.base_resolver.wrapped_func
|
49
49
|
)
|
50
50
|
|
51
51
|
return source
|
@@ -9,7 +9,7 @@ from strawberry.exceptions.utils.source_finder import SourceFinder
|
|
9
9
|
from .exception import StrawberryException
|
10
10
|
|
11
11
|
if TYPE_CHECKING:
|
12
|
-
from strawberry.
|
12
|
+
from strawberry.types.scalar import ScalarDefinition
|
13
13
|
|
14
14
|
from .exception_source import ExceptionSource
|
15
15
|
|
@@ -8,8 +8,8 @@ from strawberry.exceptions.utils.source_finder import SourceFinder
|
|
8
8
|
from .exception import StrawberryException
|
9
9
|
|
10
10
|
if TYPE_CHECKING:
|
11
|
-
from strawberry.field import StrawberryField
|
12
|
-
from strawberry.object_type import StrawberryObjectDefinition
|
11
|
+
from strawberry.types.field import StrawberryField
|
12
|
+
from strawberry.types.object_type import StrawberryObjectDefinition
|
13
13
|
|
14
14
|
from .exception_source import ExceptionSource
|
15
15
|
|
@@ -15,8 +15,8 @@ if TYPE_CHECKING:
|
|
15
15
|
|
16
16
|
from libcst import BinaryOperation, Call, CSTNode, FunctionDef
|
17
17
|
|
18
|
-
from strawberry.
|
19
|
-
from strawberry.union import StrawberryUnion
|
18
|
+
from strawberry.types.scalar import ScalarDefinition
|
19
|
+
from strawberry.types.union import StrawberryUnion
|
20
20
|
|
21
21
|
|
22
22
|
@dataclass
|
@@ -605,3 +605,6 @@ class SourceFinder:
|
|
605
605
|
if self.cst
|
606
606
|
else None
|
607
607
|
)
|
608
|
+
|
609
|
+
|
610
|
+
__all__ = ["SourceFinder"]
|
@@ -4,17 +4,17 @@ import copy
|
|
4
4
|
import dataclasses
|
5
5
|
from typing import TYPE_CHECKING, Any, Type, Union, cast
|
6
6
|
|
7
|
-
from strawberry.
|
8
|
-
from strawberry.type import (
|
7
|
+
from strawberry.types.base import (
|
9
8
|
StrawberryList,
|
10
9
|
StrawberryOptional,
|
11
10
|
has_object_definition,
|
12
11
|
)
|
13
|
-
from strawberry.
|
12
|
+
from strawberry.types.enum import EnumDefinition
|
13
|
+
from strawberry.types.union import StrawberryUnion
|
14
14
|
|
15
15
|
if TYPE_CHECKING:
|
16
|
-
from strawberry.
|
17
|
-
from strawberry.
|
16
|
+
from strawberry.types.base import StrawberryType
|
17
|
+
from strawberry.types.field import StrawberryField
|
18
18
|
|
19
19
|
|
20
20
|
def _convert_from_pydantic_to_strawberry_type(
|
@@ -6,7 +6,7 @@ from typing_extensions import Protocol
|
|
6
6
|
from pydantic import BaseModel
|
7
7
|
|
8
8
|
if TYPE_CHECKING:
|
9
|
-
from strawberry.types.
|
9
|
+
from strawberry.types.base import StrawberryObjectDefinition
|
10
10
|
|
11
11
|
|
12
12
|
PydanticModel = TypeVar("PydanticModel", bound=BaseModel)
|
@@ -14,7 +14,9 @@ PydanticModel = TypeVar("PydanticModel", bound=BaseModel)
|
|
14
14
|
|
15
15
|
class StrawberryTypeFromPydantic(Protocol[PydanticModel]):
|
16
16
|
"""This class does not exist in runtime.
|
17
|
-
|
17
|
+
|
18
|
+
It only makes the methods below visible for IDEs.
|
19
|
+
"""
|
18
20
|
|
19
21
|
def __init__(self, **kwargs: Any) -> None: ...
|
20
22
|
|
@@ -16,7 +16,6 @@ from typing import (
|
|
16
16
|
|
17
17
|
from pydantic import BaseModel
|
18
18
|
|
19
|
-
from strawberry.auto import StrawberryAuto
|
20
19
|
from strawberry.experimental.pydantic._compat import (
|
21
20
|
CompatModelField,
|
22
21
|
PydanticCompat,
|
@@ -27,7 +26,8 @@ from strawberry.experimental.pydantic.utils import (
|
|
27
26
|
get_strawberry_type_from_model,
|
28
27
|
normalize_type,
|
29
28
|
)
|
30
|
-
from strawberry.
|
29
|
+
from strawberry.types.auto import StrawberryAuto
|
30
|
+
from strawberry.types.object_type import _process_type, _wrap_dataclass
|
31
31
|
from strawberry.types.type_resolver import _get_fields
|
32
32
|
from strawberry.utils.typing import get_list_annotation, is_list
|
33
33
|
|
@@ -13,7 +13,7 @@ from strawberry.experimental.pydantic._compat import (
|
|
13
13
|
from strawberry.experimental.pydantic.exceptions import (
|
14
14
|
UnregisteredTypeException,
|
15
15
|
)
|
16
|
-
from strawberry.types.
|
16
|
+
from strawberry.types.base import StrawberryObjectDefinition
|
17
17
|
|
18
18
|
try:
|
19
19
|
from types import UnionType as TypingUnionType
|
@@ -51,7 +51,7 @@ def replace_pydantic_types(type_: Any, is_input: bool) -> Any:
|
|
51
51
|
def replace_types_recursively(
|
52
52
|
type_: Any, is_input: bool, compat: PydanticCompat
|
53
53
|
) -> Any:
|
54
|
-
"""Runs the conversions recursively into the arguments of generic types if any"""
|
54
|
+
"""Runs the conversions recursively into the arguments of generic types if any."""
|
55
55
|
basic_type = compat.get_basic_type(type_)
|
56
56
|
replaced_type = replace_pydantic_types(basic_type, is_input)
|
57
57
|
|
@@ -17,7 +17,6 @@ from typing import (
|
|
17
17
|
)
|
18
18
|
|
19
19
|
from strawberry.annotation import StrawberryAnnotation
|
20
|
-
from strawberry.auto import StrawberryAuto
|
21
20
|
from strawberry.experimental.pydantic._compat import (
|
22
21
|
CompatModelField,
|
23
22
|
PydanticCompat,
|
@@ -34,8 +33,9 @@ from strawberry.experimental.pydantic.utils import (
|
|
34
33
|
get_default_factory_for_field,
|
35
34
|
get_private_fields,
|
36
35
|
)
|
37
|
-
from strawberry.
|
38
|
-
from strawberry.
|
36
|
+
from strawberry.types.auto import StrawberryAuto
|
37
|
+
from strawberry.types.field import StrawberryField
|
38
|
+
from strawberry.types.object_type import _process_type, _wrap_dataclass
|
39
39
|
from strawberry.types.type_resolver import _get_fields
|
40
40
|
from strawberry.utils.dataclasses import add_custom_init_fn
|
41
41
|
|
@@ -312,8 +312,10 @@ def input(
|
|
312
312
|
use_pydantic_alias: bool = True,
|
313
313
|
) -> Callable[..., Type[StrawberryTypeFromPydantic[PydanticModel]]]:
|
314
314
|
"""Convenience decorator for creating an input type from a Pydantic model.
|
315
|
-
|
316
|
-
|
315
|
+
|
316
|
+
Equal to `partial(type, is_input=True)`
|
317
|
+
|
318
|
+
See https://github.com/strawberry-graphql/strawberry/issues/1830.
|
317
319
|
"""
|
318
320
|
return type(
|
319
321
|
model=model,
|
@@ -340,8 +342,10 @@ def interface(
|
|
340
342
|
use_pydantic_alias: bool = True,
|
341
343
|
) -> Callable[..., Type[StrawberryTypeFromPydantic[PydanticModel]]]:
|
342
344
|
"""Convenience decorator for creating an interface type from a Pydantic model.
|
343
|
-
|
344
|
-
|
345
|
+
|
346
|
+
Equal to `partial(type, is_interface=True)`
|
347
|
+
|
348
|
+
See https://github.com/strawberry-graphql/strawberry/issues/1830.
|
345
349
|
"""
|
346
350
|
return type(
|
347
351
|
model=model,
|
@@ -25,8 +25,8 @@ from strawberry.experimental.pydantic.exceptions import (
|
|
25
25
|
BothDefaultAndDefaultFactoryDefinedError,
|
26
26
|
UnregisteredTypeException,
|
27
27
|
)
|
28
|
-
from strawberry.private import is_private
|
29
|
-
from strawberry.unset import UNSET
|
28
|
+
from strawberry.types.private import is_private
|
29
|
+
from strawberry.types.unset import UNSET
|
30
30
|
from strawberry.utils.typing import (
|
31
31
|
get_list_annotation,
|
32
32
|
get_optional_annotation,
|
@@ -60,7 +60,7 @@ def get_private_fields(cls: Type) -> List[dataclasses.Field]:
|
|
60
60
|
|
61
61
|
|
62
62
|
class DataclassCreationFields(NamedTuple):
|
63
|
-
"""Fields required for the fields parameter of make_dataclass"""
|
63
|
+
"""Fields required for the fields parameter of make_dataclass."""
|
64
64
|
|
65
65
|
name: str
|
66
66
|
field_type: Type
|
@@ -75,8 +75,7 @@ def get_default_factory_for_field(
|
|
75
75
|
field: CompatModelField,
|
76
76
|
compat: PydanticCompat,
|
77
77
|
) -> Union[NoArgAnyCallable, dataclasses._MISSING_TYPE]:
|
78
|
-
"""
|
79
|
-
Gets the default factory for a pydantic field.
|
78
|
+
"""Gets the default factory for a pydantic field.
|
80
79
|
|
81
80
|
Handles mutable defaults when making the dataclass by
|
82
81
|
using pydantic's smart_deepcopy
|
@@ -21,7 +21,8 @@ def dataclass_init_fn(
|
|
21
21
|
self_name: str,
|
22
22
|
globals_: Dict[str, Any],
|
23
23
|
) -> Any:
|
24
|
-
"""
|
24
|
+
"""Create an __init__ function for a dataclass.
|
25
|
+
|
25
26
|
We create a custom __init__ function for the dataclasses that back
|
26
27
|
Strawberry object types to only accept keyword arguments. This allows us to
|
27
28
|
avoid the problem where a type cannot define a field with a default value
|