strawberry-graphql 0.255.0__py3-none-any.whl → 0.256.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 +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 +4 -1
- 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.0.dist-info}/METADATA +3 -6
- strawberry_graphql-0.256.0.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.0.dist-info}/LICENSE +0 -0
- {strawberry_graphql-0.255.0.dist-info → strawberry_graphql-0.256.0.dist-info}/WHEEL +0 -0
- {strawberry_graphql-0.255.0.dist-info → strawberry_graphql-0.256.0.dist-info}/entry_points.txt +0 -0
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
2
2
|
|
3
3
|
import dataclasses
|
4
4
|
import sys
|
5
|
-
from typing import Any
|
5
|
+
from typing import Any
|
6
6
|
|
7
7
|
from strawberry.annotation import StrawberryAnnotation
|
8
8
|
from strawberry.exceptions import (
|
@@ -17,8 +17,8 @@ from strawberry.types.unset import UNSET
|
|
17
17
|
|
18
18
|
|
19
19
|
def _get_fields(
|
20
|
-
cls:
|
21
|
-
) ->
|
20
|
+
cls: type[Any], original_type_annotations: dict[str, type[Any]]
|
21
|
+
) -> list[StrawberryField]:
|
22
22
|
"""Get all the strawberry fields off a strawberry.type cls.
|
23
23
|
|
24
24
|
This function returns a list of StrawberryFields (one for each field item), while
|
@@ -54,7 +54,7 @@ def _get_fields(
|
|
54
54
|
passing a named function (i.e. not an anonymous lambda) to strawberry.field
|
55
55
|
(typically as a decorator).
|
56
56
|
"""
|
57
|
-
fields:
|
57
|
+
fields: dict[str, StrawberryField] = {}
|
58
58
|
|
59
59
|
# before trying to find any fields, let's first add the fields defined in
|
60
60
|
# parent classes, we do this by checking if parents have a type definition
|
@@ -71,7 +71,7 @@ def _get_fields(
|
|
71
71
|
# Find the class the each field was originally defined on so we can use
|
72
72
|
# that scope later when resolving the type, as it may have different names
|
73
73
|
# available to it.
|
74
|
-
origins:
|
74
|
+
origins: dict[str, type] = {field_name: cls for field_name in cls.__annotations__}
|
75
75
|
|
76
76
|
for base in cls.__mro__:
|
77
77
|
if has_object_definition(base):
|
strawberry/types/union.py
CHANGED
@@ -6,20 +6,15 @@ import warnings
|
|
6
6
|
from itertools import chain
|
7
7
|
from typing import (
|
8
8
|
TYPE_CHECKING,
|
9
|
+
Annotated,
|
9
10
|
Any,
|
10
|
-
Collection,
|
11
|
-
Iterable,
|
12
|
-
List,
|
13
|
-
Mapping,
|
14
11
|
NoReturn,
|
15
12
|
Optional,
|
16
|
-
Tuple,
|
17
|
-
Type,
|
18
13
|
TypeVar,
|
19
14
|
Union,
|
20
15
|
cast,
|
21
16
|
)
|
22
|
-
from typing_extensions import
|
17
|
+
from typing_extensions import get_origin
|
23
18
|
|
24
19
|
from graphql import GraphQLNamedType, GraphQLUnionType
|
25
20
|
|
@@ -39,6 +34,8 @@ from strawberry.types.base import (
|
|
39
34
|
from strawberry.types.lazy_type import LazyType
|
40
35
|
|
41
36
|
if TYPE_CHECKING:
|
37
|
+
from collections.abc import Collection, Iterable, Mapping
|
38
|
+
|
42
39
|
from graphql import (
|
43
40
|
GraphQLAbstractType,
|
44
41
|
GraphQLResolveInfo,
|
@@ -57,7 +54,7 @@ class StrawberryUnion(StrawberryType):
|
|
57
54
|
def __init__(
|
58
55
|
self,
|
59
56
|
name: Optional[str] = None,
|
60
|
-
type_annotations:
|
57
|
+
type_annotations: tuple[StrawberryAnnotation, ...] = tuple(),
|
61
58
|
description: Optional[str] = None,
|
62
59
|
directives: Iterable[object] = (),
|
63
60
|
) -> None:
|
@@ -94,14 +91,14 @@ class StrawberryUnion(StrawberryType):
|
|
94
91
|
raise InvalidTypeForUnionMergeError(self, other)
|
95
92
|
|
96
93
|
@property
|
97
|
-
def types(self) ->
|
94
|
+
def types(self) -> tuple[StrawberryType, ...]:
|
98
95
|
return tuple(
|
99
96
|
cast(StrawberryType, annotation.resolve())
|
100
97
|
for annotation in self.type_annotations
|
101
98
|
)
|
102
99
|
|
103
100
|
@property
|
104
|
-
def type_params(self) ->
|
101
|
+
def type_params(self) -> list[TypeVar]:
|
105
102
|
def _get_type_params(type_: StrawberryType) -> list[TypeVar]:
|
106
103
|
if isinstance(type_, LazyType):
|
107
104
|
type_ = cast("StrawberryType", type_.resolve_type())
|
@@ -240,7 +237,7 @@ class StrawberryUnion(StrawberryType):
|
|
240
237
|
|
241
238
|
def union(
|
242
239
|
name: str,
|
243
|
-
types: Optional[Collection[
|
240
|
+
types: Optional[Collection[type[Any]]] = None,
|
244
241
|
*,
|
245
242
|
description: Optional[str] = None,
|
246
243
|
directives: Iterable[object] = (),
|
strawberry/types/unset.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import warnings
|
2
|
-
from typing import Any,
|
2
|
+
from typing import Any, Optional
|
3
3
|
|
4
|
-
DEPRECATED_NAMES:
|
4
|
+
DEPRECATED_NAMES: dict[str, str] = {
|
5
5
|
"is_unset": "`is_unset` is deprecated use `value is UNSET` instead",
|
6
6
|
}
|
7
7
|
|
@@ -9,7 +9,7 @@ DEPRECATED_NAMES: Dict[str, str] = {
|
|
9
9
|
class UnsetType:
|
10
10
|
__instance: Optional["UnsetType"] = None
|
11
11
|
|
12
|
-
def __new__(cls:
|
12
|
+
def __new__(cls: type["UnsetType"]) -> "UnsetType":
|
13
13
|
if cls.__instance is None:
|
14
14
|
ret = super().__new__(cls)
|
15
15
|
cls.__instance = ret
|
strawberry/utils/aio.py
CHANGED
@@ -1,14 +1,9 @@
|
|
1
1
|
import sys
|
2
|
+
from collections.abc import AsyncGenerator, AsyncIterable, AsyncIterator, Awaitable
|
2
3
|
from typing import (
|
3
4
|
Any,
|
4
|
-
AsyncGenerator,
|
5
|
-
AsyncIterable,
|
6
|
-
AsyncIterator,
|
7
|
-
Awaitable,
|
8
5
|
Callable,
|
9
|
-
List,
|
10
6
|
Optional,
|
11
|
-
Tuple,
|
12
7
|
TypeVar,
|
13
8
|
Union,
|
14
9
|
)
|
@@ -19,7 +14,7 @@ _R = TypeVar("_R")
|
|
19
14
|
|
20
15
|
async def aenumerate(
|
21
16
|
iterable: Union[AsyncIterator[_T], AsyncIterable[_T]],
|
22
|
-
) -> AsyncIterator[
|
17
|
+
) -> AsyncIterator[tuple[int, _T]]:
|
23
18
|
"""Async version of enumerate."""
|
24
19
|
i = 0
|
25
20
|
async for element in iterable:
|
@@ -56,7 +51,7 @@ async def aislice(
|
|
56
51
|
return
|
57
52
|
|
58
53
|
|
59
|
-
async def asyncgen_to_list(generator: AsyncGenerator[_T, Any]) ->
|
54
|
+
async def asyncgen_to_list(generator: AsyncGenerator[_T, Any]) -> list[_T]:
|
60
55
|
"""Convert an async generator to a list."""
|
61
56
|
return [element async for element in generator]
|
62
57
|
|
strawberry/utils/await_maybe.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import inspect
|
2
|
-
from
|
2
|
+
from collections.abc import AsyncIterator, Awaitable, Iterator
|
3
|
+
from typing import TypeVar, Union
|
3
4
|
|
4
5
|
T = TypeVar("T")
|
5
6
|
|
@@ -14,4 +15,4 @@ async def await_maybe(value: AwaitableOrValue[T]) -> T:
|
|
14
15
|
return value
|
15
16
|
|
16
17
|
|
17
|
-
__all__ = ["
|
18
|
+
__all__ = ["AsyncIteratorOrIterator", "AwaitableOrValue", "await_maybe"]
|
strawberry/utils/debug.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import datetime
|
2
2
|
import json
|
3
3
|
from json import JSONEncoder
|
4
|
-
from typing import Any,
|
4
|
+
from typing import Any, Optional
|
5
5
|
|
6
6
|
|
7
7
|
class StrawberryJSONEncoder(JSONEncoder):
|
@@ -10,7 +10,7 @@ class StrawberryJSONEncoder(JSONEncoder):
|
|
10
10
|
|
11
11
|
|
12
12
|
def pretty_print_graphql_operation(
|
13
|
-
operation_name: Optional[str], query: str, variables: Optional[
|
13
|
+
operation_name: Optional[str], query: str, variables: Optional[dict["str", Any]]
|
14
14
|
) -> None:
|
15
15
|
"""Pretty print a GraphQL operation using pygments.
|
16
16
|
|
strawberry/utils/deprecations.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
3
|
import warnings
|
4
|
-
from typing import Any, Optional
|
4
|
+
from typing import Any, Optional
|
5
5
|
|
6
6
|
|
7
7
|
class DEPRECATION_MESSAGES:
|
@@ -19,7 +19,7 @@ class DeprecatedDescriptor:
|
|
19
19
|
def warn(self) -> None:
|
20
20
|
warnings.warn(self.msg, stacklevel=2)
|
21
21
|
|
22
|
-
def __get__(self, obj: Optional[object], type: Optional[
|
22
|
+
def __get__(self, obj: Optional[object], type: Optional[type] = None) -> Any:
|
23
23
|
self.warn()
|
24
24
|
return self.alias
|
25
25
|
|
strawberry/utils/inspect.py
CHANGED
@@ -4,8 +4,6 @@ from functools import lru_cache
|
|
4
4
|
from typing import (
|
5
5
|
Any,
|
6
6
|
Callable,
|
7
|
-
Dict,
|
8
|
-
List,
|
9
7
|
Optional,
|
10
8
|
TypeVar,
|
11
9
|
get_origin,
|
@@ -27,7 +25,7 @@ def in_async_context() -> bool:
|
|
27
25
|
|
28
26
|
|
29
27
|
@lru_cache(maxsize=250)
|
30
|
-
def get_func_args(func: Callable[[Any], Any]) ->
|
28
|
+
def get_func_args(func: Callable[[Any], Any]) -> list[str]:
|
31
29
|
"""Returns a list of arguments for the function."""
|
32
30
|
sig = inspect.signature(func)
|
33
31
|
|
@@ -38,7 +36,7 @@ def get_func_args(func: Callable[[Any], Any]) -> List[str]:
|
|
38
36
|
]
|
39
37
|
|
40
38
|
|
41
|
-
def get_specialized_type_var_map(cls: type) -> Optional[
|
39
|
+
def get_specialized_type_var_map(cls: type) -> Optional[dict[str, type]]:
|
42
40
|
"""Get a type var map for specialized types.
|
43
41
|
|
44
42
|
Consider the following:
|
@@ -122,4 +120,4 @@ def get_specialized_type_var_map(cls: type) -> Optional[Dict[str, type]]:
|
|
122
120
|
return type_var_map
|
123
121
|
|
124
122
|
|
125
|
-
__all__ = ["
|
123
|
+
__all__ = ["get_func_args", "get_specialized_type_var_map", "in_async_context"]
|
@@ -26,4 +26,4 @@ def to_snake_case(name: str) -> str:
|
|
26
26
|
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", name).lower()
|
27
27
|
|
28
28
|
|
29
|
-
__all__ = ["
|
29
|
+
__all__ = ["capitalize_first", "to_camel_case", "to_kebab_case", "to_snake_case"]
|
strawberry/utils/typing.py
CHANGED
@@ -2,19 +2,15 @@ import ast
|
|
2
2
|
import dataclasses
|
3
3
|
import sys
|
4
4
|
import typing
|
5
|
+
from collections.abc import AsyncGenerator
|
5
6
|
from functools import lru_cache
|
6
7
|
from typing import ( # type: ignore
|
7
|
-
|
8
|
+
Annotated,
|
8
9
|
Any,
|
9
|
-
AsyncGenerator,
|
10
10
|
ClassVar,
|
11
|
-
Dict,
|
12
11
|
ForwardRef,
|
13
12
|
Generic,
|
14
|
-
List,
|
15
13
|
Optional,
|
16
|
-
Tuple,
|
17
|
-
Type,
|
18
14
|
TypeVar,
|
19
15
|
Union,
|
20
16
|
_eval_type,
|
@@ -23,22 +19,11 @@ from typing import ( # type: ignore
|
|
23
19
|
cast,
|
24
20
|
overload,
|
25
21
|
)
|
26
|
-
from typing_extensions import
|
27
|
-
|
28
|
-
ast_unparse = getattr(ast, "unparse", None)
|
29
|
-
# ast.unparse is only available on python 3.9+. For older versions we will
|
30
|
-
# use `astunparse.unparse`.
|
31
|
-
# We are also using "not TYPE_CHECKING" here because mypy gives an erorr
|
32
|
-
# on tests because "astunparse" is missing stubs, but the mypy action says
|
33
|
-
# that the comment is unused.
|
34
|
-
if not TYPE_CHECKING and ast_unparse is None:
|
35
|
-
import astunparse
|
36
|
-
|
37
|
-
ast_unparse = astunparse.unparse
|
22
|
+
from typing_extensions import TypeGuard, get_args, get_origin
|
38
23
|
|
39
24
|
|
40
25
|
@lru_cache
|
41
|
-
def get_generic_alias(type_:
|
26
|
+
def get_generic_alias(type_: type) -> type:
|
42
27
|
"""Get the generic alias for a type.
|
43
28
|
|
44
29
|
Given a type, its generic alias from `typing` module will be returned
|
@@ -105,21 +90,21 @@ def is_union(annotation: object) -> bool:
|
|
105
90
|
return annotation_origin == Union
|
106
91
|
|
107
92
|
|
108
|
-
def is_optional(annotation:
|
93
|
+
def is_optional(annotation: type) -> bool:
|
109
94
|
"""Returns True if the annotation is Optional[SomeType]."""
|
110
95
|
# Optionals are represented as unions
|
111
96
|
|
112
97
|
if not is_union(annotation):
|
113
98
|
return False
|
114
99
|
|
115
|
-
types = annotation.__args__
|
100
|
+
types = annotation.__args__ # type: ignore[attr-defined]
|
116
101
|
|
117
102
|
# A Union to be optional needs to have at least one None type
|
118
103
|
return any(x == None.__class__ for x in types)
|
119
104
|
|
120
105
|
|
121
|
-
def get_optional_annotation(annotation:
|
122
|
-
types = annotation.__args__
|
106
|
+
def get_optional_annotation(annotation: type) -> type:
|
107
|
+
types = annotation.__args__ # type: ignore[attr-defined]
|
123
108
|
|
124
109
|
non_none_types = tuple(x for x in types if x != None.__class__)
|
125
110
|
|
@@ -127,13 +112,13 @@ def get_optional_annotation(annotation: Type) -> Type:
|
|
127
112
|
# type (normally a Union type).
|
128
113
|
|
129
114
|
if len(non_none_types) > 1:
|
130
|
-
return annotation.copy_with(non_none_types)
|
115
|
+
return annotation.copy_with(non_none_types) # type: ignore[attr-defined]
|
131
116
|
|
132
117
|
return non_none_types[0]
|
133
118
|
|
134
119
|
|
135
|
-
def get_list_annotation(annotation:
|
136
|
-
return annotation.__args__[0]
|
120
|
+
def get_list_annotation(annotation: type) -> type:
|
121
|
+
return annotation.__args__[0] # type: ignore[attr-defined]
|
137
122
|
|
138
123
|
|
139
124
|
def is_concrete_generic(annotation: type) -> bool:
|
@@ -161,7 +146,7 @@ def is_generic(annotation: type) -> bool:
|
|
161
146
|
)
|
162
147
|
|
163
148
|
|
164
|
-
def is_type_var(annotation:
|
149
|
+
def is_type_var(annotation: type) -> bool:
|
165
150
|
"""Returns True if the annotation is a TypeVar."""
|
166
151
|
return isinstance(annotation, TypeVar)
|
167
152
|
|
@@ -186,7 +171,7 @@ def is_classvar(cls: type, annotation: Union[ForwardRef, str]) -> bool:
|
|
186
171
|
)
|
187
172
|
|
188
173
|
|
189
|
-
def type_has_annotation(type_: object, annotation:
|
174
|
+
def type_has_annotation(type_: object, annotation: type) -> bool:
|
190
175
|
"""Returns True if the type_ has been annotated with annotation."""
|
191
176
|
if get_origin(type_) is Annotated:
|
192
177
|
return any(isinstance(argument, annotation) for argument in get_args(type_))
|
@@ -194,14 +179,13 @@ def type_has_annotation(type_: object, annotation: Type) -> bool:
|
|
194
179
|
return False
|
195
180
|
|
196
181
|
|
197
|
-
def get_parameters(annotation:
|
198
|
-
if (
|
199
|
-
isinstance(annotation,
|
200
|
-
or isinstance(annotation, type)
|
182
|
+
def get_parameters(annotation: type) -> Union[tuple[object], tuple[()]]:
|
183
|
+
if isinstance(annotation, _GenericAlias) or (
|
184
|
+
isinstance(annotation, type)
|
201
185
|
and issubclass(annotation, Generic) # type:ignore
|
202
186
|
and annotation is not Generic
|
203
187
|
):
|
204
|
-
return annotation.__parameters__
|
188
|
+
return annotation.__parameters__ # type: ignore[union-attr]
|
205
189
|
else:
|
206
190
|
return () # pragma: no cover
|
207
191
|
|
@@ -238,8 +222,7 @@ def _ast_replace_union_operation(
|
|
238
222
|
if hasattr(ast, "Index") and isinstance(expr.slice, ast.Index):
|
239
223
|
expr = ast.Subscript(
|
240
224
|
expr.value,
|
241
|
-
#
|
242
|
-
ast.Index(_ast_replace_union_operation(cast(Any, expr.slice).value)), # type: ignore
|
225
|
+
ast.Index(_ast_replace_union_operation(expr.slice.value)), # type: ignore
|
243
226
|
ast.Load(),
|
244
227
|
)
|
245
228
|
elif isinstance(expr.slice, (ast.BinOp, ast.Tuple)):
|
@@ -254,9 +237,9 @@ def _ast_replace_union_operation(
|
|
254
237
|
|
255
238
|
def _get_namespace_from_ast(
|
256
239
|
expr: Union[ast.Expr, ast.expr],
|
257
|
-
globalns: Optional[
|
258
|
-
localns: Optional[
|
259
|
-
) ->
|
240
|
+
globalns: Optional[dict] = None,
|
241
|
+
localns: Optional[dict] = None,
|
242
|
+
) -> dict[str, type]:
|
260
243
|
from strawberry.types.lazy_type import StrawberryLazyReference
|
261
244
|
|
262
245
|
extra = {}
|
@@ -274,7 +257,6 @@ def _get_namespace_from_ast(
|
|
274
257
|
and expr.value.id == "Union"
|
275
258
|
):
|
276
259
|
if hasattr(ast, "Index") and isinstance(expr.slice, ast.Index):
|
277
|
-
# The cast is required for mypy on python 3.7 and 3.8
|
278
260
|
expr_slice = cast(Any, expr.slice).value
|
279
261
|
else:
|
280
262
|
expr_slice = expr.slice
|
@@ -292,18 +274,15 @@ def _get_namespace_from_ast(
|
|
292
274
|
and isinstance(expr.value, ast.Name)
|
293
275
|
and expr.value.id == "Annotated"
|
294
276
|
):
|
295
|
-
assert ast_unparse
|
296
|
-
|
297
277
|
if hasattr(ast, "Index") and isinstance(expr.slice, ast.Index):
|
298
|
-
# The cast is required for mypy on python 3.7 and 3.8
|
299
278
|
expr_slice = cast(Any, expr.slice).value
|
300
279
|
else:
|
301
280
|
expr_slice = expr.slice
|
302
281
|
|
303
|
-
args:
|
282
|
+
args: list[str] = []
|
304
283
|
for elt in cast(ast.Tuple, expr_slice).elts:
|
305
284
|
extra.update(_get_namespace_from_ast(elt, globalns, localns))
|
306
|
-
args.append(
|
285
|
+
args.append(ast.unparse(elt))
|
307
286
|
|
308
287
|
# When using forward refs, the whole
|
309
288
|
# Annotated[SomeType, strawberry.lazy("type.module")] is a forward ref,
|
@@ -322,16 +301,16 @@ def _get_namespace_from_ast(
|
|
322
301
|
|
323
302
|
def eval_type(
|
324
303
|
type_: Any,
|
325
|
-
globalns: Optional[
|
326
|
-
localns: Optional[
|
327
|
-
) ->
|
304
|
+
globalns: Optional[dict] = None,
|
305
|
+
localns: Optional[dict] = None,
|
306
|
+
) -> type:
|
328
307
|
"""Evaluates a type, resolving forward references."""
|
329
308
|
from strawberry.types.auto import StrawberryAuto
|
330
309
|
from strawberry.types.lazy_type import StrawberryLazyReference
|
331
310
|
from strawberry.types.private import StrawberryPrivate
|
332
311
|
|
333
312
|
globalns = globalns or {}
|
334
|
-
# If this is not a string, maybe its args are (e.g.
|
313
|
+
# If this is not a string, maybe its args are (e.g. list["Foo"])
|
335
314
|
if isinstance(type_, ForwardRef):
|
336
315
|
ast_obj = cast(ast.Expr, ast.parse(type_.__forward_arg__).body[0])
|
337
316
|
|
@@ -347,10 +326,9 @@ def eval_type(
|
|
347
326
|
|
348
327
|
globalns.update(_get_namespace_from_ast(ast_obj, globalns, localns))
|
349
328
|
|
350
|
-
|
351
|
-
type_ = ForwardRef(ast_unparse(ast_obj))
|
329
|
+
type_ = ForwardRef(ast.unparse(ast_obj))
|
352
330
|
|
353
|
-
extra:
|
331
|
+
extra: dict[str, Any] = {}
|
354
332
|
|
355
333
|
if sys.version_info >= (3, 13):
|
356
334
|
extra = {"type_params": None}
|
@@ -400,13 +378,6 @@ def eval_type(
|
|
400
378
|
if origin is UnionType:
|
401
379
|
origin = Union
|
402
380
|
|
403
|
-
# Future annotations in older versions will eval generic aliases to their
|
404
|
-
# real types (i.e. List[foo] will have its origin set to list instead
|
405
|
-
# of List). If that type is not subscriptable, retrieve its generic
|
406
|
-
# alias version instead.
|
407
|
-
if sys.version_info < (3, 9) and not hasattr(origin, "__class_getitem__"):
|
408
|
-
origin = get_generic_alias(origin)
|
409
|
-
|
410
381
|
type_ = (
|
411
382
|
origin[tuple(eval_type(a, globalns, localns) for a in args)]
|
412
383
|
if args
|
@@ -417,19 +388,19 @@ def eval_type(
|
|
417
388
|
|
418
389
|
|
419
390
|
__all__ = [
|
391
|
+
"eval_type",
|
420
392
|
"get_generic_alias",
|
421
|
-
"is_generic_alias",
|
422
|
-
"is_list",
|
423
|
-
"is_union",
|
424
|
-
"is_optional",
|
425
|
-
"get_optional_annotation",
|
426
393
|
"get_list_annotation",
|
394
|
+
"get_optional_annotation",
|
395
|
+
"get_parameters",
|
396
|
+
"is_classvar",
|
427
397
|
"is_concrete_generic",
|
428
|
-
"is_generic_subclass",
|
429
398
|
"is_generic",
|
399
|
+
"is_generic_alias",
|
400
|
+
"is_generic_subclass",
|
401
|
+
"is_list",
|
402
|
+
"is_optional",
|
430
403
|
"is_type_var",
|
431
|
-
"
|
404
|
+
"is_union",
|
432
405
|
"type_has_annotation",
|
433
|
-
"get_parameters",
|
434
|
-
"eval_type",
|
435
406
|
]
|
@@ -1,18 +1,17 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: strawberry-graphql
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.256.0
|
4
4
|
Summary: A library for creating GraphQL APIs
|
5
5
|
Home-page: https://strawberry.rocks/
|
6
6
|
License: MIT
|
7
7
|
Keywords: graphql,api,rest,starlette,async
|
8
8
|
Author: Patrick Arminio
|
9
9
|
Author-email: patrick.arminio@gmail.com
|
10
|
-
Requires-Python: >=3.
|
10
|
+
Requires-Python: >=3.9,<4.0
|
11
11
|
Classifier: Development Status :: 5 - Production/Stable
|
12
12
|
Classifier: Intended Audience :: Developers
|
13
13
|
Classifier: License :: OSI Approved :: MIT License
|
14
14
|
Classifier: Programming Language :: Python :: 3
|
15
|
-
Classifier: Programming Language :: Python :: 3.8
|
16
15
|
Classifier: Programming Language :: Python :: 3.9
|
17
16
|
Classifier: Programming Language :: Python :: 3.10
|
18
17
|
Classifier: Programming Language :: Python :: 3.11
|
@@ -39,15 +38,13 @@ Provides-Extra: sanic
|
|
39
38
|
Requires-Dist: Django (>=3.2) ; extra == "django"
|
40
39
|
Requires-Dist: aiohttp (>=3.7.4.post0,<4.0.0) ; extra == "aiohttp"
|
41
40
|
Requires-Dist: asgiref (>=3.2,<4.0) ; extra == "django" or extra == "channels"
|
42
|
-
Requires-Dist: astunparse (>=1.6.3,<2.0.0) ; python_version < "3.9"
|
43
41
|
Requires-Dist: chalice (>=1.22,<2.0) ; extra == "chalice"
|
44
42
|
Requires-Dist: channels (>=3.0.5) ; extra == "channels"
|
45
43
|
Requires-Dist: fastapi (>=0.65.2) ; extra == "fastapi"
|
46
44
|
Requires-Dist: flask (>=1.1) ; extra == "flask"
|
47
|
-
Requires-Dist: graphlib_backport ; (python_version < "3.9") and (extra == "cli")
|
48
45
|
Requires-Dist: graphql-core (>=3.2.0,<3.4.0)
|
49
46
|
Requires-Dist: libcst (>=0.4.7) ; extra == "debug" or extra == "debug-server" or extra == "cli"
|
50
|
-
Requires-Dist: litestar (>=2) ;
|
47
|
+
Requires-Dist: litestar (>=2) ; extra == "litestar"
|
51
48
|
Requires-Dist: opentelemetry-api (<2) ; extra == "opentelemetry"
|
52
49
|
Requires-Dist: opentelemetry-sdk (<2) ; extra == "opentelemetry"
|
53
50
|
Requires-Dist: pydantic (>1.6.1) ; extra == "pydantic"
|