strawberry-graphql 0.283.0__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.

Files changed (146) hide show
  1. strawberry/aiohttp/test/client.py +8 -15
  2. strawberry/aiohttp/views.py +12 -15
  3. strawberry/annotation.py +19 -23
  4. strawberry/asgi/__init__.py +18 -17
  5. strawberry/asgi/test/client.py +6 -6
  6. strawberry/chalice/views.py +6 -6
  7. strawberry/channels/handlers/base.py +7 -8
  8. strawberry/channels/handlers/http_handler.py +18 -20
  9. strawberry/channels/handlers/ws_handler.py +10 -12
  10. strawberry/channels/router.py +3 -4
  11. strawberry/channels/testing.py +7 -9
  12. strawberry/cli/commands/codegen.py +7 -7
  13. strawberry/cli/commands/schema_codegen.py +1 -2
  14. strawberry/cli/commands/upgrade/__init__.py +1 -3
  15. strawberry/cli/commands/upgrade/_run_codemod.py +2 -2
  16. strawberry/codegen/plugins/print_operation.py +2 -2
  17. strawberry/codegen/plugins/python.py +2 -2
  18. strawberry/codegen/query_codegen.py +20 -30
  19. strawberry/codegen/types.py +32 -32
  20. strawberry/codemods/annotated_unions.py +2 -2
  21. strawberry/dataloader.py +28 -24
  22. strawberry/directive.py +6 -7
  23. strawberry/django/test/client.py +3 -3
  24. strawberry/django/views.py +16 -19
  25. strawberry/exceptions/__init__.py +4 -4
  26. strawberry/exceptions/conflicting_arguments.py +2 -2
  27. strawberry/exceptions/duplicated_type_name.py +4 -4
  28. strawberry/exceptions/exception.py +3 -3
  29. strawberry/exceptions/handler.py +8 -7
  30. strawberry/exceptions/invalid_argument_type.py +2 -2
  31. strawberry/exceptions/invalid_superclass_interface.py +2 -2
  32. strawberry/exceptions/invalid_union_type.py +4 -4
  33. strawberry/exceptions/missing_arguments_annotations.py +2 -2
  34. strawberry/exceptions/missing_dependencies.py +2 -4
  35. strawberry/exceptions/missing_field_annotation.py +2 -2
  36. strawberry/exceptions/missing_return_annotation.py +2 -2
  37. strawberry/exceptions/object_is_not_a_class.py +2 -2
  38. strawberry/exceptions/object_is_not_an_enum.py +2 -2
  39. strawberry/exceptions/permission_fail_silently_requires_optional.py +2 -2
  40. strawberry/exceptions/private_strawberry_field.py +2 -2
  41. strawberry/exceptions/scalar_already_registered.py +2 -2
  42. strawberry/exceptions/syntax.py +3 -3
  43. strawberry/exceptions/unresolved_field_type.py +2 -2
  44. strawberry/exceptions/utils/source_finder.py +25 -25
  45. strawberry/experimental/pydantic/_compat.py +8 -7
  46. strawberry/experimental/pydantic/conversion.py +2 -2
  47. strawberry/experimental/pydantic/conversion_types.py +2 -2
  48. strawberry/experimental/pydantic/error_type.py +10 -12
  49. strawberry/experimental/pydantic/fields.py +9 -15
  50. strawberry/experimental/pydantic/object_type.py +15 -23
  51. strawberry/experimental/pydantic/utils.py +1 -2
  52. strawberry/ext/mypy_plugin.py +12 -14
  53. strawberry/extensions/base_extension.py +2 -1
  54. strawberry/extensions/context.py +13 -18
  55. strawberry/extensions/directives.py +3 -1
  56. strawberry/extensions/field_extension.py +4 -4
  57. strawberry/extensions/max_aliases.py +1 -3
  58. strawberry/extensions/parser_cache.py +1 -2
  59. strawberry/extensions/query_depth_limiter.py +18 -14
  60. strawberry/extensions/runner.py +2 -2
  61. strawberry/extensions/tracing/apollo.py +3 -3
  62. strawberry/extensions/tracing/datadog.py +3 -3
  63. strawberry/extensions/tracing/opentelemetry.py +6 -8
  64. strawberry/extensions/tracing/utils.py +3 -1
  65. strawberry/extensions/utils.py +2 -2
  66. strawberry/extensions/validation_cache.py +1 -2
  67. strawberry/fastapi/context.py +6 -6
  68. strawberry/fastapi/router.py +33 -36
  69. strawberry/federation/argument.py +4 -5
  70. strawberry/federation/enum.py +18 -21
  71. strawberry/federation/field.py +94 -97
  72. strawberry/federation/object_type.py +56 -58
  73. strawberry/federation/scalar.py +27 -35
  74. strawberry/federation/schema.py +15 -16
  75. strawberry/federation/schema_directive.py +7 -6
  76. strawberry/federation/schema_directives.py +11 -11
  77. strawberry/federation/union.py +4 -4
  78. strawberry/flask/views.py +10 -11
  79. strawberry/http/__init__.py +14 -14
  80. strawberry/http/async_base_view.py +23 -28
  81. strawberry/http/base.py +11 -12
  82. strawberry/http/ides.py +2 -3
  83. strawberry/http/sync_base_view.py +11 -13
  84. strawberry/http/types.py +3 -3
  85. strawberry/litestar/controller.py +40 -35
  86. strawberry/permission.py +4 -6
  87. strawberry/printer/ast_from_value.py +3 -5
  88. strawberry/printer/printer.py +8 -13
  89. strawberry/quart/views.py +12 -14
  90. strawberry/relay/exceptions.py +4 -4
  91. strawberry/relay/fields.py +33 -32
  92. strawberry/relay/types.py +31 -34
  93. strawberry/relay/utils.py +2 -2
  94. strawberry/resolvers.py +2 -1
  95. strawberry/sanic/context.py +1 -0
  96. strawberry/sanic/utils.py +3 -3
  97. strawberry/sanic/views.py +11 -14
  98. strawberry/scalars.py +2 -2
  99. strawberry/schema/_graphql_core.py +5 -5
  100. strawberry/schema/base.py +32 -33
  101. strawberry/schema/compat.py +9 -9
  102. strawberry/schema/config.py +5 -2
  103. strawberry/schema/exceptions.py +1 -3
  104. strawberry/schema/name_converter.py +6 -6
  105. strawberry/schema/schema.py +55 -60
  106. strawberry/schema/schema_converter.py +27 -22
  107. strawberry/schema/types/base_scalars.py +1 -1
  108. strawberry/schema/types/concrete_type.py +5 -5
  109. strawberry/schema_codegen/__init__.py +3 -3
  110. strawberry/schema_directive.py +7 -6
  111. strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py +5 -6
  112. strawberry/subscriptions/protocols/graphql_transport_ws/types.py +20 -20
  113. strawberry/subscriptions/protocols/graphql_ws/handlers.py +5 -6
  114. strawberry/subscriptions/protocols/graphql_ws/types.py +14 -14
  115. strawberry/test/client.py +18 -18
  116. strawberry/tools/create_type.py +2 -3
  117. strawberry/types/arguments.py +25 -26
  118. strawberry/types/auto.py +3 -4
  119. strawberry/types/base.py +25 -27
  120. strawberry/types/enum.py +22 -25
  121. strawberry/types/execution.py +14 -15
  122. strawberry/types/field.py +108 -108
  123. strawberry/types/fields/resolver.py +19 -21
  124. strawberry/types/info.py +5 -11
  125. strawberry/types/lazy_type.py +2 -3
  126. strawberry/types/maybe.py +12 -3
  127. strawberry/types/mutation.py +115 -118
  128. strawberry/types/nodes.py +2 -2
  129. strawberry/types/object_type.py +43 -63
  130. strawberry/types/scalar.py +37 -43
  131. strawberry/types/union.py +12 -14
  132. strawberry/utils/aio.py +12 -9
  133. strawberry/utils/await_maybe.py +3 -3
  134. strawberry/utils/deprecations.py +2 -2
  135. strawberry/utils/importer.py +1 -2
  136. strawberry/utils/inspect.py +4 -6
  137. strawberry/utils/logging.py +2 -2
  138. strawberry/utils/operation.py +4 -4
  139. strawberry/utils/typing.py +18 -83
  140. {strawberry_graphql-0.283.0.dist-info → strawberry_graphql-0.284.3.dist-info}/METADATA +2 -2
  141. strawberry_graphql-0.284.3.dist-info/RECORD +243 -0
  142. strawberry/utils/dataclasses.py +0 -37
  143. strawberry_graphql-0.283.0.dist-info/RECORD +0 -244
  144. {strawberry_graphql-0.283.0.dist-info → strawberry_graphql-0.284.3.dist-info}/WHEEL +0 -0
  145. {strawberry_graphql-0.283.0.dist-info → strawberry_graphql-0.284.3.dist-info}/entry_points.txt +0 -0
  146. {strawberry_graphql-0.283.0.dist-info → strawberry_graphql-0.284.3.dist-info}/licenses/LICENSE +0 -0
strawberry/types/enum.py CHANGED
@@ -1,12 +1,9 @@
1
1
  import dataclasses
2
- from collections.abc import Iterable, Mapping
2
+ from collections.abc import Callable, Iterable, Mapping
3
3
  from enum import EnumMeta
4
4
  from typing import (
5
5
  Any,
6
- Callable,
7
- Optional,
8
6
  TypeVar,
9
- Union,
10
7
  overload,
11
8
  )
12
9
 
@@ -18,9 +15,9 @@ from strawberry.types.base import StrawberryType
18
15
  class EnumValue:
19
16
  name: str
20
17
  value: Any
21
- deprecation_reason: Optional[str] = None
18
+ deprecation_reason: str | None = None
22
19
  directives: Iterable[object] = ()
23
- description: Optional[str] = None
20
+ description: str | None = None
24
21
 
25
22
 
26
23
  @dataclasses.dataclass
@@ -28,7 +25,7 @@ class EnumDefinition(StrawberryType):
28
25
  wrapped_cls: EnumMeta
29
26
  name: str
30
27
  values: list[EnumValue]
31
- description: Optional[str]
28
+ description: str | None
32
29
  directives: Iterable[object] = ()
33
30
 
34
31
  def __hash__(self) -> int:
@@ -36,8 +33,8 @@ class EnumDefinition(StrawberryType):
36
33
  return hash(self.name)
37
34
 
38
35
  def copy_with(
39
- self, type_var_map: Mapping[str, Union[StrawberryType, type]]
40
- ) -> Union[StrawberryType, type]:
36
+ self, type_var_map: Mapping[str, StrawberryType | type]
37
+ ) -> StrawberryType | type:
41
38
  # enum don't support type parameters, so we can safely return self
42
39
  return self
43
40
 
@@ -54,10 +51,10 @@ class EnumDefinition(StrawberryType):
54
51
  @dataclasses.dataclass
55
52
  class EnumValueDefinition:
56
53
  value: Any
57
- graphql_name: Optional[str] = None
58
- deprecation_reason: Optional[str] = None
54
+ graphql_name: str | None = None
55
+ deprecation_reason: str | None = None
59
56
  directives: Iterable[object] = ()
60
- description: Optional[str] = None
57
+ description: str | None = None
61
58
 
62
59
  def __int__(self) -> int:
63
60
  return self.value
@@ -65,10 +62,10 @@ class EnumValueDefinition:
65
62
 
66
63
  def enum_value(
67
64
  value: Any,
68
- name: Optional[str] = None,
69
- deprecation_reason: Optional[str] = None,
65
+ name: str | None = None,
66
+ deprecation_reason: str | None = None,
70
67
  directives: Iterable[object] = (),
71
- description: Optional[str] = None,
68
+ description: str | None = None,
72
69
  ) -> EnumValueDefinition:
73
70
  """Function to customise an enum value, for example to add a description or deprecation reason.
74
71
 
@@ -109,8 +106,8 @@ EnumType = TypeVar("EnumType", bound=EnumMeta)
109
106
 
110
107
  def _process_enum(
111
108
  cls: EnumType,
112
- name: Optional[str] = None,
113
- description: Optional[str] = None,
109
+ name: str | None = None,
110
+ description: str | None = None,
114
111
  directives: Iterable[object] = (),
115
112
  ) -> EnumType:
116
113
  if not isinstance(cls, EnumMeta):
@@ -166,8 +163,8 @@ def _process_enum(
166
163
  def enum(
167
164
  cls: EnumType,
168
165
  *,
169
- name: Optional[str] = None,
170
- description: Optional[str] = None,
166
+ name: str | None = None,
167
+ description: str | None = None,
171
168
  directives: Iterable[object] = (),
172
169
  ) -> EnumType: ...
173
170
 
@@ -176,19 +173,19 @@ def enum(
176
173
  def enum(
177
174
  cls: None = None,
178
175
  *,
179
- name: Optional[str] = None,
180
- description: Optional[str] = None,
176
+ name: str | None = None,
177
+ description: str | None = None,
181
178
  directives: Iterable[object] = (),
182
179
  ) -> Callable[[EnumType], EnumType]: ...
183
180
 
184
181
 
185
182
  def enum(
186
- cls: Optional[EnumType] = None,
183
+ cls: EnumType | None = None,
187
184
  *,
188
- name: Optional[str] = None,
189
- description: Optional[str] = None,
185
+ name: str | None = None,
186
+ description: str | None = None,
190
187
  directives: Iterable[object] = (),
191
- ) -> Union[EnumType, Callable[[EnumType], EnumType]]:
188
+ ) -> EnumType | Callable[[EnumType], EnumType]:
192
189
  """Annotates an Enum class a GraphQL enum.
193
190
 
194
191
  GraphQL enums only have names, while Python enums have names and values,
@@ -4,7 +4,6 @@ import dataclasses
4
4
  from typing import (
5
5
  TYPE_CHECKING,
6
6
  Any,
7
- Optional,
8
7
  runtime_checkable,
9
8
  )
10
9
  from typing_extensions import Protocol, TypedDict, deprecated
@@ -29,36 +28,36 @@ if TYPE_CHECKING:
29
28
 
30
29
  @dataclasses.dataclass
31
30
  class ExecutionContext:
32
- query: Optional[str]
31
+ query: str | None
33
32
  schema: Schema
34
33
  allowed_operations: Iterable[OperationType]
35
34
  context: Any = None
36
- variables: Optional[dict[str, Any]] = None
35
+ variables: dict[str, Any] | None = None
37
36
  parse_options: ParseOptions = dataclasses.field(
38
37
  default_factory=lambda: ParseOptions()
39
38
  )
40
- root_value: Optional[Any] = None
39
+ root_value: Any | None = None
41
40
  validation_rules: tuple[type[ASTValidationRule], ...] = dataclasses.field(
42
41
  default_factory=lambda: tuple(specified_rules)
43
42
  )
44
43
 
45
44
  # The operation name that is provided by the request
46
- provided_operation_name: dataclasses.InitVar[Optional[str]] = None
45
+ provided_operation_name: dataclasses.InitVar[str | None] = None
47
46
 
48
47
  # Values that get populated during the GraphQL execution so that they can be
49
48
  # accessed by extensions
50
- graphql_document: Optional[DocumentNode] = None
51
- pre_execution_errors: Optional[list[GraphQLError]] = None
52
- result: Optional[GraphQLExecutionResult] = None
49
+ graphql_document: DocumentNode | None = None
50
+ pre_execution_errors: list[GraphQLError] | None = None
51
+ result: GraphQLExecutionResult | None = None
53
52
  extensions_results: dict[str, Any] = dataclasses.field(default_factory=dict)
54
53
 
55
- operation_extensions: Optional[dict[str, Any]] = None
54
+ operation_extensions: dict[str, Any] | None = None
56
55
 
57
56
  def __post_init__(self, provided_operation_name: str | None) -> None:
58
57
  self._provided_operation_name = provided_operation_name
59
58
 
60
59
  @property
61
- def operation_name(self) -> Optional[str]:
60
+ def operation_name(self) -> str | None:
62
61
  if self._provided_operation_name is not None:
63
62
  return self._provided_operation_name
64
63
 
@@ -79,7 +78,7 @@ class ExecutionContext:
79
78
 
80
79
  return get_operation_type(graphql_document, self.operation_name)
81
80
 
82
- def _get_first_operation(self) -> Optional[OperationDefinitionNode]:
81
+ def _get_first_operation(self) -> OperationDefinitionNode | None:
83
82
  graphql_document = self.graphql_document
84
83
  if not graphql_document:
85
84
  return None
@@ -88,16 +87,16 @@ class ExecutionContext:
88
87
 
89
88
  @property
90
89
  @deprecated("Use 'pre_execution_errors' instead")
91
- def errors(self) -> Optional[list[GraphQLError]]:
90
+ def errors(self) -> list[GraphQLError] | None:
92
91
  """Deprecated: Use pre_execution_errors instead."""
93
92
  return self.pre_execution_errors
94
93
 
95
94
 
96
95
  @dataclasses.dataclass
97
96
  class ExecutionResult:
98
- data: Optional[dict[str, Any]]
99
- errors: Optional[list[GraphQLError]]
100
- extensions: Optional[dict[str, Any]] = None
97
+ data: dict[str, Any] | None
98
+ errors: list[GraphQLError] | None
99
+ extensions: dict[str, Any] | None = None
101
100
 
102
101
 
103
102
  @dataclasses.dataclass
strawberry/types/field.py CHANGED
@@ -4,13 +4,13 @@ import contextlib
4
4
  import copy
5
5
  import dataclasses
6
6
  import sys
7
- from collections.abc import Awaitable, Coroutine, Mapping, Sequence
7
+ from collections.abc import Awaitable, Callable, Coroutine, Mapping, Sequence
8
8
  from functools import cached_property
9
9
  from typing import (
10
10
  TYPE_CHECKING,
11
11
  Any,
12
- Callable,
13
- Optional,
12
+ NoReturn,
13
+ TypeAlias,
14
14
  TypeVar,
15
15
  Union,
16
16
  overload,
@@ -29,7 +29,8 @@ from .fields.resolver import StrawberryResolver
29
29
 
30
30
  if TYPE_CHECKING:
31
31
  import builtins
32
- from typing_extensions import Literal, Self
32
+ from typing import Literal
33
+ from typing_extensions import Self
33
34
 
34
35
  from strawberry.extensions.field_extension import FieldExtension
35
36
  from strawberry.permission import BasePermission
@@ -39,24 +40,31 @@ if TYPE_CHECKING:
39
40
 
40
41
  T = TypeVar("T")
41
42
 
42
- _RESOLVER_TYPE_SYNC = Union[
43
+ _RESOLVER_TYPE_SYNC: TypeAlias = Union[
43
44
  StrawberryResolver[T],
44
45
  Callable[..., T],
45
46
  "staticmethod[Any, T]",
46
47
  "classmethod[Any, Any, T]",
47
48
  ]
48
49
 
49
- _RESOLVER_TYPE_ASYNC = Union[
50
- Callable[..., Coroutine[Any, Any, T]],
51
- Callable[..., Awaitable[T]],
52
- ]
50
+ _RESOLVER_TYPE_ASYNC: TypeAlias = (
51
+ Callable[..., Coroutine[Any, Any, T]] | Callable[..., Awaitable[T]]
52
+ )
53
+
54
+ _RESOLVER_TYPE: TypeAlias = _RESOLVER_TYPE_SYNC[T] | _RESOLVER_TYPE_ASYNC[T]
53
55
 
54
- _RESOLVER_TYPE = Union[_RESOLVER_TYPE_SYNC[T], _RESOLVER_TYPE_ASYNC[T]]
55
56
 
56
- UNRESOLVED = object()
57
+ class UNRESOLVED:
58
+ def __new__(cls) -> NoReturn:
59
+ raise TypeError("UNRESOLVED is a sentinel and cannot be instantiated.")
57
60
 
58
61
 
59
- def _is_generic(resolver_type: Union[StrawberryType, type]) -> bool:
62
+ FieldType: TypeAlias = (
63
+ StrawberryType | type[WithStrawberryObjectDefinition | UNRESOLVED]
64
+ )
65
+
66
+
67
+ def _is_generic(resolver_type: StrawberryType | type) -> bool:
60
68
  """Returns True if `resolver_type` is generic else False."""
61
69
  if isinstance(resolver_type, StrawberryType):
62
70
  return resolver_type.is_graphql_generic
@@ -69,34 +77,36 @@ def _is_generic(resolver_type: Union[StrawberryType, type]) -> bool:
69
77
 
70
78
 
71
79
  class StrawberryField(dataclasses.Field):
72
- type_annotation: Optional[StrawberryAnnotation]
80
+ type_annotation: StrawberryAnnotation | None
73
81
  default_resolver: Callable[[Any, str], object] = getattr
74
82
 
75
83
  def __init__(
76
84
  self,
77
- python_name: Optional[str] = None,
78
- graphql_name: Optional[str] = None,
79
- type_annotation: Optional[StrawberryAnnotation] = None,
80
- origin: Optional[Union[type, Callable, staticmethod, classmethod]] = None,
85
+ python_name: str | None = None,
86
+ graphql_name: str | None = None,
87
+ type_annotation: StrawberryAnnotation | None = None,
88
+ origin: type | Callable | staticmethod | classmethod | None = None,
81
89
  is_subscription: bool = False,
82
- description: Optional[str] = None,
83
- base_resolver: Optional[StrawberryResolver] = None,
90
+ description: str | None = None,
91
+ base_resolver: StrawberryResolver | None = None,
84
92
  permission_classes: list[type[BasePermission]] = (), # type: ignore
85
93
  default: object = dataclasses.MISSING,
86
- default_factory: Union[Callable[[], Any], object] = dataclasses.MISSING,
87
- metadata: Optional[Mapping[Any, Any]] = None,
88
- deprecation_reason: Optional[str] = None,
94
+ default_factory: Callable[[], Any] | object = dataclasses.MISSING,
95
+ metadata: Mapping[Any, Any] | None = None,
96
+ deprecation_reason: str | None = None,
89
97
  directives: Sequence[object] = (),
90
98
  extensions: list[FieldExtension] = (), # type: ignore
91
99
  ) -> None:
92
100
  # basic fields are fields with no provided resolver
93
101
  is_basic_field = not base_resolver
94
102
 
95
- kwargs: Any = {}
103
+ kwargs: Any = {
104
+ "kw_only": True,
105
+ }
96
106
 
97
- # kw_only was added to python 3.10 and it is required
98
- if sys.version_info >= (3, 10):
99
- kwargs["kw_only"] = dataclasses.MISSING
107
+ # doc was added to python 3.14 and it is required
108
+ if sys.version_info >= (3, 14):
109
+ kwargs["doc"] = None
100
110
 
101
111
  super().__init__(
102
112
  default=default,
@@ -115,11 +125,11 @@ class StrawberryField(dataclasses.Field):
115
125
 
116
126
  self.type_annotation = type_annotation
117
127
 
118
- self.description: Optional[str] = description
128
+ self.description: str | None = description
119
129
  self.origin = origin
120
130
 
121
- self._arguments: Optional[list[StrawberryArgument]] = None
122
- self._base_resolver: Optional[StrawberryResolver] = None
131
+ self._arguments: list[StrawberryArgument] | None = None
132
+ self._base_resolver: StrawberryResolver | None = None
123
133
  if base_resolver is not None:
124
134
  self.base_resolver = base_resolver
125
135
 
@@ -211,8 +221,8 @@ class StrawberryField(dataclasses.Field):
211
221
  return self
212
222
 
213
223
  def get_result(
214
- self, source: Any, info: Optional[Info], args: list[Any], kwargs: Any
215
- ) -> Union[Awaitable[Any], Any]:
224
+ self, source: Any, info: Info | None, args: list[Any], kwargs: Any
225
+ ) -> Awaitable[Any] | Any:
216
226
  """Calls the resolver defined for the StrawberryField.
217
227
 
218
228
  If the field doesn't have a resolver defined we default
@@ -254,7 +264,7 @@ class StrawberryField(dataclasses.Field):
254
264
  else _is_generic(self.type)
255
265
  )
256
266
 
257
- def _python_name(self) -> Optional[str]:
267
+ def _python_name(self) -> str | None:
258
268
  if self.name:
259
269
  return self.name
260
270
 
@@ -269,7 +279,7 @@ class StrawberryField(dataclasses.Field):
269
279
  python_name: str = property(_python_name, _set_python_name) # type: ignore[assignment]
270
280
 
271
281
  @property
272
- def base_resolver(self) -> Optional[StrawberryResolver]:
282
+ def base_resolver(self) -> StrawberryResolver | None:
273
283
  return self._base_resolver
274
284
 
275
285
  @base_resolver.setter
@@ -292,14 +302,8 @@ class StrawberryField(dataclasses.Field):
292
302
  # removed.
293
303
  _ = resolver.arguments
294
304
 
295
- @property # type: ignore
296
- def type(
297
- self,
298
- ) -> Union[ # type: ignore [valid-type]
299
- StrawberryType,
300
- type[WithStrawberryObjectDefinition],
301
- Literal[UNRESOLVED],
302
- ]:
305
+ @property
306
+ def type(self) -> FieldType:
303
307
  return self.resolve_type()
304
308
 
305
309
  @type.setter
@@ -329,15 +333,11 @@ class StrawberryField(dataclasses.Field):
329
333
  def resolve_type(
330
334
  self,
331
335
  *,
332
- type_definition: Optional[StrawberryObjectDefinition] = None,
333
- ) -> Union[ # type: ignore [valid-type]
334
- StrawberryType,
335
- type[WithStrawberryObjectDefinition],
336
- Literal[UNRESOLVED],
337
- ]:
336
+ type_definition: StrawberryObjectDefinition | None = None,
337
+ ) -> FieldType:
338
338
  # We return UNRESOLVED by default, which means this case will raise a
339
339
  # MissingReturnAnnotationError exception in _check_field_annotations
340
- resolved = UNRESOLVED
340
+ resolved: FieldType = UNRESOLVED # type: ignore[assignment]
341
341
 
342
342
  # We are catching NameError because dataclasses tries to fetch the type
343
343
  # of the field from the class before the class is fully defined.
@@ -358,13 +358,13 @@ class StrawberryField(dataclasses.Field):
358
358
  return resolved
359
359
 
360
360
  def copy_with(
361
- self, type_var_map: Mapping[str, Union[StrawberryType, builtins.type]]
361
+ self, type_var_map: Mapping[str, StrawberryType | builtins.type]
362
362
  ) -> Self:
363
363
  new_field = copy.copy(self)
364
364
 
365
- override_type: Optional[
366
- Union[StrawberryType, type[WithStrawberryObjectDefinition]]
367
- ] = None
365
+ override_type: StrawberryType | type[WithStrawberryObjectDefinition] | None = (
366
+ None
367
+ )
368
368
  type_ = self.resolve_type()
369
369
  if has_object_definition(type_):
370
370
  type_definition = type_.__strawberry_definition__
@@ -405,18 +405,18 @@ class StrawberryField(dataclasses.Field):
405
405
  def field(
406
406
  *,
407
407
  resolver: _RESOLVER_TYPE_ASYNC[T],
408
- name: Optional[str] = None,
408
+ name: str | None = None,
409
409
  is_subscription: bool = False,
410
- description: Optional[str] = None,
410
+ description: str | None = None,
411
411
  init: Literal[False] = False,
412
- permission_classes: Optional[list[type[BasePermission]]] = None,
413
- deprecation_reason: Optional[str] = None,
412
+ permission_classes: list[type[BasePermission]] | None = None,
413
+ deprecation_reason: str | None = None,
414
414
  default: Any = dataclasses.MISSING,
415
- default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
416
- metadata: Optional[Mapping[Any, Any]] = None,
417
- directives: Optional[Sequence[object]] = (),
418
- extensions: Optional[list[FieldExtension]] = None,
419
- graphql_type: Optional[Any] = None,
415
+ default_factory: Callable[..., object] | object = dataclasses.MISSING,
416
+ metadata: Mapping[Any, Any] | None = None,
417
+ directives: Sequence[object] | None = (),
418
+ extensions: list[FieldExtension] | None = None,
419
+ graphql_type: Any | None = None,
420
420
  ) -> T: ...
421
421
 
422
422
 
@@ -424,36 +424,36 @@ def field(
424
424
  def field(
425
425
  *,
426
426
  resolver: _RESOLVER_TYPE_SYNC[T],
427
- name: Optional[str] = None,
427
+ name: str | None = None,
428
428
  is_subscription: bool = False,
429
- description: Optional[str] = None,
429
+ description: str | None = None,
430
430
  init: Literal[False] = False,
431
- permission_classes: Optional[list[type[BasePermission]]] = None,
432
- deprecation_reason: Optional[str] = None,
431
+ permission_classes: list[type[BasePermission]] | None = None,
432
+ deprecation_reason: str | None = None,
433
433
  default: Any = dataclasses.MISSING,
434
- default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
435
- metadata: Optional[Mapping[Any, Any]] = None,
436
- directives: Optional[Sequence[object]] = (),
437
- extensions: Optional[list[FieldExtension]] = None,
438
- graphql_type: Optional[Any] = None,
434
+ default_factory: Callable[..., object] | object = dataclasses.MISSING,
435
+ metadata: Mapping[Any, Any] | None = None,
436
+ directives: Sequence[object] | None = (),
437
+ extensions: list[FieldExtension] | None = None,
438
+ graphql_type: Any | None = None,
439
439
  ) -> T: ...
440
440
 
441
441
 
442
442
  @overload
443
443
  def field(
444
444
  *,
445
- name: Optional[str] = None,
445
+ name: str | None = None,
446
446
  is_subscription: bool = False,
447
- description: Optional[str] = None,
447
+ description: str | None = None,
448
448
  init: Literal[True] = True,
449
- permission_classes: Optional[list[type[BasePermission]]] = None,
450
- deprecation_reason: Optional[str] = None,
449
+ permission_classes: list[type[BasePermission]] | None = None,
450
+ deprecation_reason: str | None = None,
451
451
  default: Any = dataclasses.MISSING,
452
- default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
453
- metadata: Optional[Mapping[Any, Any]] = None,
454
- directives: Optional[Sequence[object]] = (),
455
- extensions: Optional[list[FieldExtension]] = None,
456
- graphql_type: Optional[Any] = None,
452
+ default_factory: Callable[..., object] | object = dataclasses.MISSING,
453
+ metadata: Mapping[Any, Any] | None = None,
454
+ directives: Sequence[object] | None = (),
455
+ extensions: list[FieldExtension] | None = None,
456
+ graphql_type: Any | None = None,
457
457
  ) -> Any: ...
458
458
 
459
459
 
@@ -461,17 +461,17 @@ def field(
461
461
  def field(
462
462
  resolver: _RESOLVER_TYPE_ASYNC[T],
463
463
  *,
464
- name: Optional[str] = None,
464
+ name: str | None = None,
465
465
  is_subscription: bool = False,
466
- description: Optional[str] = None,
467
- permission_classes: Optional[list[type[BasePermission]]] = None,
468
- deprecation_reason: Optional[str] = None,
466
+ description: str | None = None,
467
+ permission_classes: list[type[BasePermission]] | None = None,
468
+ deprecation_reason: str | None = None,
469
469
  default: Any = dataclasses.MISSING,
470
- default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
471
- metadata: Optional[Mapping[Any, Any]] = None,
472
- directives: Optional[Sequence[object]] = (),
473
- extensions: Optional[list[FieldExtension]] = None,
474
- graphql_type: Optional[Any] = None,
470
+ default_factory: Callable[..., object] | object = dataclasses.MISSING,
471
+ metadata: Mapping[Any, Any] | None = None,
472
+ directives: Sequence[object] | None = (),
473
+ extensions: list[FieldExtension] | None = None,
474
+ graphql_type: Any | None = None,
475
475
  ) -> StrawberryField: ...
476
476
 
477
477
 
@@ -479,38 +479,38 @@ def field(
479
479
  def field(
480
480
  resolver: _RESOLVER_TYPE_SYNC[T],
481
481
  *,
482
- name: Optional[str] = None,
482
+ name: str | None = None,
483
483
  is_subscription: bool = False,
484
- description: Optional[str] = None,
485
- permission_classes: Optional[list[type[BasePermission]]] = None,
486
- deprecation_reason: Optional[str] = None,
484
+ description: str | None = None,
485
+ permission_classes: list[type[BasePermission]] | None = None,
486
+ deprecation_reason: str | None = None,
487
487
  default: Any = dataclasses.MISSING,
488
- default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
489
- metadata: Optional[Mapping[Any, Any]] = None,
490
- directives: Optional[Sequence[object]] = (),
491
- extensions: Optional[list[FieldExtension]] = None,
492
- graphql_type: Optional[Any] = None,
488
+ default_factory: Callable[..., object] | object = dataclasses.MISSING,
489
+ metadata: Mapping[Any, Any] | None = None,
490
+ directives: Sequence[object] | None = (),
491
+ extensions: list[FieldExtension] | None = None,
492
+ graphql_type: Any | None = None,
493
493
  ) -> StrawberryField: ...
494
494
 
495
495
 
496
496
  def field(
497
- resolver: Optional[_RESOLVER_TYPE[Any]] = None,
497
+ resolver: _RESOLVER_TYPE[Any] | None = None,
498
498
  *,
499
- name: Optional[str] = None,
499
+ name: str | None = None,
500
500
  is_subscription: bool = False,
501
- description: Optional[str] = None,
502
- permission_classes: Optional[list[type[BasePermission]]] = None,
503
- deprecation_reason: Optional[str] = None,
501
+ description: str | None = None,
502
+ permission_classes: list[type[BasePermission]] | None = None,
503
+ deprecation_reason: str | None = None,
504
504
  default: Any = dataclasses.MISSING,
505
- default_factory: Union[Callable[..., object], object] = dataclasses.MISSING,
506
- metadata: Optional[Mapping[Any, Any]] = None,
507
- directives: Optional[Sequence[object]] = (),
508
- extensions: Optional[list[FieldExtension]] = None,
509
- graphql_type: Optional[Any] = None,
505
+ default_factory: Callable[..., object] | object = dataclasses.MISSING,
506
+ metadata: Mapping[Any, Any] | None = None,
507
+ directives: Sequence[object] | None = (),
508
+ extensions: list[FieldExtension] | None = None,
509
+ graphql_type: Any | None = None,
510
510
  # This init parameter is used by PyRight to determine whether this field
511
511
  # is added in the constructor or not. It is not used to change
512
512
  # any behavior at the moment.
513
- init: Literal[True, False, None] = None,
513
+ init: Literal[True, False] | None = None,
514
514
  ) -> Any:
515
515
  """Annotates a method or property as a GraphQL field.
516
516