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.

Files changed (161) hide show
  1. strawberry/__init__.py +2 -0
  2. strawberry/aiohttp/test/client.py +8 -15
  3. strawberry/aiohttp/views.py +15 -64
  4. strawberry/annotation.py +70 -25
  5. strawberry/asgi/__init__.py +22 -56
  6. strawberry/asgi/test/client.py +6 -6
  7. strawberry/chalice/views.py +13 -79
  8. strawberry/channels/handlers/base.py +7 -8
  9. strawberry/channels/handlers/http_handler.py +50 -32
  10. strawberry/channels/handlers/ws_handler.py +12 -14
  11. strawberry/channels/router.py +3 -4
  12. strawberry/channels/testing.py +7 -9
  13. strawberry/cli/__init__.py +7 -6
  14. strawberry/cli/commands/codegen.py +7 -7
  15. strawberry/cli/commands/dev.py +72 -0
  16. strawberry/cli/commands/schema_codegen.py +1 -2
  17. strawberry/cli/commands/server.py +3 -44
  18. strawberry/cli/commands/upgrade/__init__.py +3 -3
  19. strawberry/cli/commands/upgrade/_run_codemod.py +2 -2
  20. strawberry/cli/constants.py +1 -2
  21. strawberry/cli/{debug_server.py → dev_server.py} +3 -7
  22. strawberry/codegen/plugins/print_operation.py +2 -2
  23. strawberry/codegen/plugins/python.py +2 -2
  24. strawberry/codegen/query_codegen.py +20 -30
  25. strawberry/codegen/types.py +32 -32
  26. strawberry/codemods/__init__.py +9 -0
  27. strawberry/codemods/annotated_unions.py +2 -2
  28. strawberry/codemods/maybe_optional.py +118 -0
  29. strawberry/dataloader.py +28 -24
  30. strawberry/directive.py +6 -7
  31. strawberry/django/test/client.py +3 -3
  32. strawberry/django/views.py +21 -91
  33. strawberry/exceptions/__init__.py +4 -4
  34. strawberry/exceptions/conflicting_arguments.py +2 -2
  35. strawberry/exceptions/duplicated_type_name.py +4 -4
  36. strawberry/exceptions/exception.py +3 -3
  37. strawberry/exceptions/handler.py +8 -7
  38. strawberry/exceptions/invalid_argument_type.py +2 -2
  39. strawberry/exceptions/invalid_superclass_interface.py +2 -2
  40. strawberry/exceptions/invalid_union_type.py +4 -4
  41. strawberry/exceptions/missing_arguments_annotations.py +2 -2
  42. strawberry/exceptions/missing_dependencies.py +2 -4
  43. strawberry/exceptions/missing_field_annotation.py +2 -2
  44. strawberry/exceptions/missing_return_annotation.py +2 -2
  45. strawberry/exceptions/object_is_not_a_class.py +2 -2
  46. strawberry/exceptions/object_is_not_an_enum.py +2 -2
  47. strawberry/exceptions/permission_fail_silently_requires_optional.py +2 -2
  48. strawberry/exceptions/private_strawberry_field.py +2 -2
  49. strawberry/exceptions/scalar_already_registered.py +2 -2
  50. strawberry/exceptions/syntax.py +3 -3
  51. strawberry/exceptions/unresolved_field_type.py +2 -2
  52. strawberry/exceptions/utils/source_finder.py +25 -25
  53. strawberry/experimental/pydantic/_compat.py +8 -7
  54. strawberry/experimental/pydantic/conversion.py +2 -2
  55. strawberry/experimental/pydantic/conversion_types.py +2 -2
  56. strawberry/experimental/pydantic/error_type.py +10 -12
  57. strawberry/experimental/pydantic/fields.py +9 -15
  58. strawberry/experimental/pydantic/object_type.py +17 -25
  59. strawberry/experimental/pydantic/utils.py +1 -2
  60. strawberry/ext/mypy_plugin.py +12 -14
  61. strawberry/extensions/base_extension.py +2 -1
  62. strawberry/extensions/context.py +13 -18
  63. strawberry/extensions/directives.py +9 -3
  64. strawberry/extensions/field_extension.py +4 -4
  65. strawberry/extensions/mask_errors.py +24 -13
  66. strawberry/extensions/max_aliases.py +1 -3
  67. strawberry/extensions/parser_cache.py +1 -2
  68. strawberry/extensions/query_depth_limiter.py +18 -14
  69. strawberry/extensions/runner.py +2 -2
  70. strawberry/extensions/tracing/apollo.py +3 -3
  71. strawberry/extensions/tracing/datadog.py +3 -3
  72. strawberry/extensions/tracing/opentelemetry.py +6 -8
  73. strawberry/extensions/tracing/utils.py +3 -1
  74. strawberry/extensions/utils.py +2 -2
  75. strawberry/extensions/validation_cache.py +2 -3
  76. strawberry/fastapi/context.py +6 -6
  77. strawberry/fastapi/router.py +43 -42
  78. strawberry/federation/argument.py +4 -5
  79. strawberry/federation/enum.py +18 -21
  80. strawberry/federation/field.py +94 -97
  81. strawberry/federation/object_type.py +56 -58
  82. strawberry/federation/scalar.py +27 -35
  83. strawberry/federation/schema.py +15 -16
  84. strawberry/federation/schema_directive.py +7 -6
  85. strawberry/federation/schema_directives.py +11 -11
  86. strawberry/federation/union.py +4 -4
  87. strawberry/flask/views.py +16 -85
  88. strawberry/http/__init__.py +30 -20
  89. strawberry/http/async_base_view.py +208 -89
  90. strawberry/http/base.py +28 -11
  91. strawberry/http/exceptions.py +5 -7
  92. strawberry/http/ides.py +2 -3
  93. strawberry/http/sync_base_view.py +115 -69
  94. strawberry/http/types.py +3 -3
  95. strawberry/litestar/controller.py +43 -77
  96. strawberry/permission.py +4 -6
  97. strawberry/printer/ast_from_value.py +3 -5
  98. strawberry/printer/printer.py +18 -15
  99. strawberry/quart/views.py +16 -48
  100. strawberry/relay/exceptions.py +4 -4
  101. strawberry/relay/fields.py +33 -32
  102. strawberry/relay/types.py +32 -35
  103. strawberry/relay/utils.py +11 -23
  104. strawberry/resolvers.py +2 -1
  105. strawberry/sanic/context.py +1 -0
  106. strawberry/sanic/utils.py +3 -3
  107. strawberry/sanic/views.py +15 -54
  108. strawberry/scalars.py +2 -2
  109. strawberry/schema/_graphql_core.py +55 -0
  110. strawberry/schema/base.py +32 -33
  111. strawberry/schema/compat.py +9 -9
  112. strawberry/schema/config.py +10 -1
  113. strawberry/schema/exceptions.py +1 -3
  114. strawberry/schema/name_converter.py +9 -8
  115. strawberry/schema/schema.py +133 -100
  116. strawberry/schema/schema_converter.py +96 -58
  117. strawberry/schema/types/base_scalars.py +1 -1
  118. strawberry/schema/types/concrete_type.py +5 -5
  119. strawberry/schema/validation_rules/maybe_null.py +136 -0
  120. strawberry/schema_codegen/__init__.py +3 -3
  121. strawberry/schema_directive.py +7 -6
  122. strawberry/static/graphiql.html +5 -5
  123. strawberry/streamable.py +35 -0
  124. strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py +5 -16
  125. strawberry/subscriptions/protocols/graphql_transport_ws/types.py +20 -20
  126. strawberry/subscriptions/protocols/graphql_ws/handlers.py +5 -12
  127. strawberry/subscriptions/protocols/graphql_ws/types.py +14 -14
  128. strawberry/test/client.py +18 -18
  129. strawberry/tools/create_type.py +2 -3
  130. strawberry/types/arguments.py +41 -28
  131. strawberry/types/auto.py +3 -4
  132. strawberry/types/base.py +25 -27
  133. strawberry/types/enum.py +22 -25
  134. strawberry/types/execution.py +21 -16
  135. strawberry/types/field.py +109 -130
  136. strawberry/types/fields/resolver.py +19 -21
  137. strawberry/types/info.py +5 -11
  138. strawberry/types/lazy_type.py +2 -3
  139. strawberry/types/maybe.py +12 -3
  140. strawberry/types/mutation.py +115 -118
  141. strawberry/types/nodes.py +2 -2
  142. strawberry/types/object_type.py +43 -63
  143. strawberry/types/scalar.py +37 -43
  144. strawberry/types/union.py +12 -14
  145. strawberry/utils/aio.py +12 -9
  146. strawberry/utils/await_maybe.py +3 -3
  147. strawberry/utils/deprecations.py +2 -2
  148. strawberry/utils/importer.py +1 -2
  149. strawberry/utils/inspect.py +4 -6
  150. strawberry/utils/logging.py +2 -2
  151. strawberry/utils/operation.py +4 -4
  152. strawberry/utils/typing.py +18 -83
  153. {strawberry_graphql-0.275.7.dist-info → strawberry_graphql-0.284.3.dist-info}/METADATA +14 -8
  154. strawberry_graphql-0.284.3.dist-info/RECORD +243 -0
  155. {strawberry_graphql-0.275.7.dist-info → strawberry_graphql-0.284.3.dist-info}/WHEEL +1 -1
  156. strawberry/utils/dataclasses.py +0 -37
  157. strawberry/utils/debug.py +0 -46
  158. strawberry/utils/graphql_lexer.py +0 -35
  159. strawberry_graphql-0.275.7.dist-info/RECORD +0 -241
  160. {strawberry_graphql-0.275.7.dist-info → strawberry_graphql-0.284.3.dist-info}/entry_points.txt +0 -0
  161. {strawberry_graphql-0.275.7.dist-info → strawberry_graphql-0.284.3.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,72 @@
1
+ import os
2
+ import sys
3
+ from enum import Enum
4
+ from typing import Annotated
5
+
6
+ import rich
7
+ import typer
8
+
9
+ from strawberry.cli.app import app
10
+ from strawberry.cli.constants import DEV_SERVER_SCHEMA_ENV_VAR_KEY
11
+ from strawberry.cli.utils import load_schema
12
+
13
+
14
+ class LogLevel(str, Enum):
15
+ critical = "critical"
16
+ error = "error"
17
+ warning = "warning"
18
+ info = "info"
19
+ debug = "debug"
20
+ trace = "trace"
21
+
22
+
23
+ @app.command(help="Starts the dev server")
24
+ def dev(
25
+ schema: str,
26
+ host: Annotated[
27
+ str, typer.Option("-h", "--host", help="Host to bind the server to.")
28
+ ] = "0.0.0.0", # noqa: S104
29
+ port: Annotated[
30
+ int, typer.Option("-p", "--port", help="Port to bind the server to.")
31
+ ] = 8000,
32
+ log_level: Annotated[
33
+ LogLevel,
34
+ typer.Option(
35
+ "--log-level", help="Passed to uvicorn to determine the server log level."
36
+ ),
37
+ ] = LogLevel.error,
38
+ app_dir: Annotated[
39
+ str,
40
+ typer.Option(
41
+ "--app-dir",
42
+ help="Look for the schema module in the specified directory, by adding this to the PYTHONPATH. Defaults to the current working directory.",
43
+ ),
44
+ ] = ".",
45
+ ) -> None:
46
+ try:
47
+ import starlette # noqa: F401
48
+ import uvicorn
49
+ except ImportError:
50
+ rich.print(
51
+ "[red]Error: The dev server requires additional packages, install them by running:\n"
52
+ r"pip install 'strawberry-graphql\[cli]'"
53
+ )
54
+ raise typer.Exit(1) from None
55
+
56
+ sys.path.insert(0, app_dir)
57
+ load_schema(schema, app_dir=app_dir)
58
+
59
+ os.environ[DEV_SERVER_SCHEMA_ENV_VAR_KEY] = schema
60
+ asgi_app = "strawberry.cli.dev_server:app"
61
+
62
+ end = " 🍓\n" if sys.platform != "win32" else "\n"
63
+ rich.print(f"Running strawberry on http://{host}:{port}/graphql", end=end)
64
+
65
+ uvicorn.run(
66
+ asgi_app,
67
+ host=host,
68
+ port=port,
69
+ log_level=log_level,
70
+ reload=True,
71
+ reload_dirs=[app_dir],
72
+ )
@@ -1,5 +1,4 @@
1
1
  from pathlib import Path
2
- from typing import Optional
3
2
 
4
3
  import typer
5
4
 
@@ -10,7 +9,7 @@ from strawberry.schema_codegen import codegen
10
9
  @app.command(help="Generate code from a query")
11
10
  def schema_codegen(
12
11
  schema: Path = typer.Argument(exists=True),
13
- output: Optional[Path] = typer.Option(
12
+ output: Path | None = typer.Option(
14
13
  None,
15
14
  "-o",
16
15
  "--output",
@@ -1,16 +1,8 @@
1
- import os
2
- import sys
3
1
  from enum import Enum
4
2
 
5
- import rich
6
3
  import typer
7
4
 
8
5
  from strawberry.cli.app import app
9
- from strawberry.cli.constants import (
10
- DEBUG_SERVER_LOG_OPERATIONS,
11
- DEBUG_SERVER_SCHEMA_ENV_VAR_KEY,
12
- )
13
- from strawberry.cli.utils import load_schema
14
6
 
15
7
 
16
8
  class LogLevel(str, Enum):
@@ -42,41 +34,8 @@ def server(
42
34
  "Works the same as `--app-dir` in uvicorn."
43
35
  ),
44
36
  ),
45
- log_operations: bool = typer.Option(
46
- True,
47
- "--log-operations",
48
- show_default=True,
49
- help="Log GraphQL operations",
50
- ),
51
37
  ) -> None:
52
- sys.path.insert(0, app_dir)
53
-
54
- try:
55
- import starlette # noqa: F401
56
- import uvicorn
57
- except ImportError:
58
- rich.print(
59
- "[red]Error: The debug server requires additional packages, "
60
- "install them by running:\n"
61
- r"pip install 'strawberry-graphql\[debug-server]'"
62
- )
63
- raise typer.Exit(1) # noqa: B904
64
-
65
- load_schema(schema, app_dir=app_dir)
66
-
67
- os.environ[DEBUG_SERVER_SCHEMA_ENV_VAR_KEY] = schema
68
- os.environ[DEBUG_SERVER_LOG_OPERATIONS] = str(log_operations)
69
- app = "strawberry.cli.debug_server:app"
70
-
71
- # Windows doesn't support UTF-8 by default
72
- endl = " 🍓\n" if sys.platform != "win32" else "\n"
73
- print(f"Running strawberry on http://{host}:{port}/graphql", end=endl) # noqa: T201
74
-
75
- uvicorn.run(
76
- app,
77
- host=host,
78
- port=port,
79
- log_level=log_level,
80
- reload=True,
81
- reload_dirs=[app_dir],
38
+ typer.echo(
39
+ "The `strawberry server` command is deprecated, use `strawberry dev` instead."
82
40
  )
41
+ raise typer.Exit(1)
@@ -10,6 +10,7 @@ from libcst.codemod import CodemodContext
10
10
 
11
11
  from strawberry.cli.app import app
12
12
  from strawberry.codemods.annotated_unions import ConvertUnionToAnnotatedUnion
13
+ from strawberry.codemods.maybe_optional import ConvertMaybeToOptional
13
14
  from strawberry.codemods.update_imports import UpdateImportsCodemod
14
15
 
15
16
  from ._run_codemod import run_codemod
@@ -17,6 +18,7 @@ from ._run_codemod import run_codemod
17
18
  codemods = {
18
19
  "annotated-union": ConvertUnionToAnnotatedUnion,
19
20
  "update-imports": UpdateImportsCodemod,
21
+ "maybe-optional": ConvertMaybeToOptional,
20
22
  }
21
23
 
22
24
 
@@ -45,8 +47,6 @@ def upgrade(
45
47
 
46
48
  raise typer.Exit(2)
47
49
 
48
- python_target_version = tuple(int(x) for x in python_target.split("."))
49
-
50
50
  transformer: ConvertUnionToAnnotatedUnion | UpdateImportsCodemod
51
51
 
52
52
  if codemod == "update-imports":
@@ -55,7 +55,7 @@ def upgrade(
55
55
  else:
56
56
  transformer = ConvertUnionToAnnotatedUnion(
57
57
  CodemodContext(),
58
- use_pipe_syntax=python_target_version >= (3, 10),
58
+ use_pipe_syntax=True,
59
59
  use_typing_extensions=use_typing_extensions,
60
60
  )
61
61
 
@@ -4,7 +4,7 @@ import contextlib
4
4
  import os
5
5
  from importlib.metadata import version
6
6
  from multiprocessing import Pool, cpu_count
7
- from typing import TYPE_CHECKING, Any, Union
7
+ from typing import TYPE_CHECKING, Any, TypeAlias
8
8
 
9
9
  from libcst.codemod._cli import ExecutionConfig, ExecutionResult, _execute_transform
10
10
  from rich.progress import Progress
@@ -16,7 +16,7 @@ if TYPE_CHECKING:
16
16
 
17
17
  from libcst.codemod import Codemod
18
18
 
19
- ProgressType = Union[type[Progress], type[FakeProgress]]
19
+ ProgressType: TypeAlias = type[Progress] | type[FakeProgress]
20
20
 
21
21
 
22
22
  def _get_libcst_version() -> tuple[int, int, int]:
@@ -1,2 +1 @@
1
- DEBUG_SERVER_SCHEMA_ENV_VAR_KEY = "STRAWBERRY_DEBUG_SERVER_SCHEMA"
2
- DEBUG_SERVER_LOG_OPERATIONS = "STRAWBERRY_DEBUG_SERVER_LOG_OPERATIONS"
1
+ DEV_SERVER_SCHEMA_ENV_VAR_KEY = "STRAWBERRY_DEV_SERVER_SCHEMA"
@@ -6,10 +6,7 @@ from starlette.middleware.cors import CORSMiddleware
6
6
 
7
7
  from strawberry import Schema
8
8
  from strawberry.asgi import GraphQL
9
- from strawberry.cli.constants import (
10
- DEBUG_SERVER_LOG_OPERATIONS,
11
- DEBUG_SERVER_SCHEMA_ENV_VAR_KEY,
12
- )
9
+ from strawberry.cli.constants import DEV_SERVER_SCHEMA_ENV_VAR_KEY
13
10
  from strawberry.utils.importer import import_module_symbol
14
11
 
15
12
  app = Starlette(debug=True)
@@ -17,12 +14,11 @@ app.add_middleware(
17
14
  CORSMiddleware, allow_headers=["*"], allow_origins=["*"], allow_methods=["*"]
18
15
  )
19
16
 
20
- schema_import_string = os.environ[DEBUG_SERVER_SCHEMA_ENV_VAR_KEY]
17
+ schema_import_string = os.environ[DEV_SERVER_SCHEMA_ENV_VAR_KEY]
21
18
  schema_symbol = import_module_symbol(schema_import_string, default_symbol_name="schema")
22
- log_operations = os.environ[DEBUG_SERVER_LOG_OPERATIONS] == "True"
23
19
 
24
20
  assert isinstance(schema_symbol, Schema)
25
- graphql_app = GraphQL[Any, Any](schema_symbol, debug=log_operations)
21
+ graphql_app = GraphQL[Any, Any](schema_symbol)
26
22
 
27
23
  paths = ["/", "/graphql"]
28
24
  for path in paths:
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import textwrap
4
- from typing import TYPE_CHECKING, Optional
4
+ from typing import TYPE_CHECKING
5
5
 
6
6
  from strawberry.codegen import CodegenFile, QueryCodegenPlugin
7
7
  from strawberry.codegen.types import (
@@ -93,7 +93,7 @@ class PrintOperationPlugin(QueryCodegenPlugin):
93
93
  return f"({variables})"
94
94
 
95
95
  def _print_graphql_type(
96
- self, type: GraphQLType, parent_type: Optional[GraphQLType] = None
96
+ self, type: GraphQLType, parent_type: GraphQLType | None = None
97
97
  ) -> str:
98
98
  if isinstance(type, GraphQLOptional):
99
99
  return self._print_graphql_type(type.of_type, type)
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  import textwrap
4
4
  from collections import defaultdict
5
5
  from dataclasses import dataclass
6
- from typing import TYPE_CHECKING, ClassVar, Optional
6
+ from typing import TYPE_CHECKING, ClassVar
7
7
 
8
8
  from strawberry.codegen import CodegenFile, QueryCodegenPlugin
9
9
  from strawberry.codegen.types import (
@@ -31,7 +31,7 @@ if TYPE_CHECKING:
31
31
  @dataclass
32
32
  class PythonType:
33
33
  type: str
34
- module: Optional[str] = None
34
+ module: str | None = None
35
35
 
36
36
 
37
37
  class PythonPlugin(QueryCodegenPlugin):
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- from collections.abc import Iterable, Mapping, Sequence
3
+ from collections.abc import Callable, Iterable, Mapping, Sequence
4
4
  from dataclasses import MISSING, dataclass
5
5
  from enum import Enum
6
6
  from functools import cmp_to_key, partial
@@ -8,12 +8,9 @@ from pathlib import Path
8
8
  from typing import (
9
9
  TYPE_CHECKING,
10
10
  Any,
11
- Callable,
12
- Optional,
13
- Union,
14
11
  cast,
15
12
  )
16
- from typing_extensions import Literal, Protocol
13
+ from typing_extensions import Protocol
17
14
 
18
15
  import rich
19
16
  from graphql import (
@@ -122,7 +119,7 @@ class CodegenResult:
122
119
 
123
120
 
124
121
  class HasSelectionSet(Protocol):
125
- selection_set: Optional[SelectionSetNode]
122
+ selection_set: SelectionSetNode | None
126
123
 
127
124
 
128
125
  class QueryCodegenPlugin:
@@ -234,7 +231,7 @@ class QueryCodegenPluginManager:
234
231
  def __init__(
235
232
  self,
236
233
  plugins: list[QueryCodegenPlugin],
237
- console_plugin: Optional[ConsolePlugin] = None,
234
+ console_plugin: ConsolePlugin | None = None,
238
235
  ) -> None:
239
236
  self.plugins = plugins
240
237
  self.console_plugin = console_plugin
@@ -298,7 +295,7 @@ class QueryCodegen:
298
295
  self,
299
296
  schema: Schema,
300
297
  plugins: list[QueryCodegenPlugin],
301
- console_plugin: Optional[ConsolePlugin] = None,
298
+ console_plugin: ConsolePlugin | None = None,
302
299
  ) -> None:
303
300
  self.schema = schema
304
301
  self.plugin_manager = QueryCodegenPluginManager(plugins, console_plugin)
@@ -390,7 +387,7 @@ class QueryCodegen:
390
387
  raise ValueError(f"Unsupported type: {type(selection)}") # pragma: no cover
391
388
 
392
389
  def _convert_selection_set(
393
- self, selection_set: Optional[SelectionSetNode]
390
+ self, selection_set: SelectionSetNode | None
394
391
  ) -> list[GraphQLSelection]:
395
392
  if selection_set is None:
396
393
  return []
@@ -473,18 +470,13 @@ class QueryCodegen:
473
470
  class_name=result_class_name,
474
471
  )
475
472
 
476
- operation_kind = cast(
477
- "Literal['query', 'mutation', 'subscription']",
478
- operation_definition.operation.value,
479
- )
480
-
481
473
  variables, variables_type = self._convert_variable_definitions(
482
474
  operation_definition.variable_definitions, operation_name=operation_name
483
475
  )
484
476
 
485
477
  return GraphQLOperation(
486
478
  operation_definition.name.value,
487
- kind=operation_kind,
479
+ kind=operation_definition.operation.value,
488
480
  selections=self._convert_selection_set(operation_definition.selection_set),
489
481
  directives=self._convert_directives(operation_definition.directives),
490
482
  variables=variables,
@@ -494,9 +486,9 @@ class QueryCodegen:
494
486
 
495
487
  def _convert_variable_definitions(
496
488
  self,
497
- variable_definitions: Optional[Iterable[VariableDefinitionNode]],
489
+ variable_definitions: Iterable[VariableDefinitionNode] | None,
498
490
  operation_name: str,
499
- ) -> tuple[list[GraphQLVariable], Optional[GraphQLObjectType]]:
491
+ ) -> tuple[list[GraphQLVariable], GraphQLObjectType | None]:
500
492
  if not variable_definitions:
501
493
  return [], None
502
494
 
@@ -527,7 +519,7 @@ class QueryCodegen:
527
519
 
528
520
  def _get_field_type(
529
521
  self,
530
- field_type: Union[StrawberryType, type],
522
+ field_type: StrawberryType | type,
531
523
  ) -> GraphQLType:
532
524
  if isinstance(field_type, StrawberryOptional):
533
525
  return GraphQLOptional(self._get_field_type(field_type.of_type))
@@ -557,7 +549,7 @@ class QueryCodegen:
557
549
  raise ValueError(f"Unsupported type: {field_type}") # pragma: no cover
558
550
 
559
551
  def _collect_type_from_strawberry_type(
560
- self, strawberry_type: Union[type, StrawberryType]
552
+ self, strawberry_type: type | StrawberryType
561
553
  ) -> GraphQLType:
562
554
  type_: GraphQLType
563
555
 
@@ -596,9 +588,9 @@ class QueryCodegen:
596
588
  return type_
597
589
 
598
590
  def _collect_type_from_variable(
599
- self, variable_type: TypeNode, parent_type: Optional[TypeNode] = None
591
+ self, variable_type: TypeNode, parent_type: TypeNode | None = None
600
592
  ) -> GraphQLType:
601
- type_: Optional[GraphQLType] = None
593
+ type_: GraphQLType | None = None
602
594
 
603
595
  if isinstance(variable_type, ListTypeNode):
604
596
  type_ = GraphQLList(
@@ -637,11 +629,9 @@ class QueryCodegen:
637
629
  )
638
630
 
639
631
  def _unwrap_type(
640
- self, type_: Union[type, StrawberryType]
641
- ) -> tuple[
642
- Union[type, StrawberryType], Optional[Callable[[GraphQLType], GraphQLType]]
643
- ]:
644
- wrapper: Optional[Callable[[GraphQLType], GraphQLType]] = None
632
+ self, type_: type | StrawberryType
633
+ ) -> tuple[type | StrawberryType, Callable[[GraphQLType], GraphQLType] | None]:
634
+ wrapper: Callable[[GraphQLType], GraphQLType] | None = None
645
635
 
646
636
  if isinstance(type_, StrawberryOptional):
647
637
  type_, previous_wrapper = self._unwrap_type(type_.of_type)
@@ -738,7 +728,7 @@ class QueryCodegen:
738
728
  selection: HasSelectionSet,
739
729
  parent_type: StrawberryObjectDefinition,
740
730
  class_name: str,
741
- ) -> Union[GraphQLObjectType, GraphQLUnion]:
731
+ ) -> GraphQLObjectType | GraphQLUnion:
742
732
  sub_types = self._collect_types_using_fragments(
743
733
  selection, parent_type, class_name
744
734
  )
@@ -773,7 +763,7 @@ class QueryCodegen:
773
763
  )
774
764
 
775
765
  current_type = graph_ql_object_type_factory(class_name)
776
- fields: list[Union[GraphQLFragmentSpread, GraphQLField]] = []
766
+ fields: list[GraphQLFragmentSpread | GraphQLField] = []
777
767
 
778
768
  for sub_selection in selection_set.selections:
779
769
  if isinstance(sub_selection, FragmentSpreadNode):
@@ -844,7 +834,7 @@ class QueryCodegen:
844
834
  list(common_fields),
845
835
  graphql_typename=type_condition_name,
846
836
  )
847
- fields: list[Union[GraphQLFragmentSpread, GraphQLField]] = []
837
+ fields: list[GraphQLFragmentSpread | GraphQLField] = []
848
838
 
849
839
  for sub_selection in fragment.selection_set.selections:
850
840
  if isinstance(sub_selection, FragmentSpreadNode):
@@ -899,7 +889,7 @@ class QueryCodegen:
899
889
  return sub_types
900
890
 
901
891
  def _collect_scalar(
902
- self, scalar_definition: ScalarDefinition, python_type: Optional[type]
892
+ self, scalar_definition: ScalarDefinition, python_type: type | None
903
893
  ) -> GraphQLScalar:
904
894
  graphql_scalar = GraphQLScalar(scalar_definition.name, python_type=python_type)
905
895
 
@@ -1,12 +1,12 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from dataclasses import dataclass, field
4
- from typing import TYPE_CHECKING, Optional, Union
4
+ from typing import TYPE_CHECKING, TypeAlias
5
5
 
6
6
  if TYPE_CHECKING:
7
7
  from collections.abc import Mapping
8
8
  from enum import EnumMeta
9
- from typing_extensions import Literal
9
+ from typing import Literal
10
10
 
11
11
  from strawberry.types.unset import UnsetType
12
12
 
@@ -30,9 +30,9 @@ class GraphQLUnion:
30
30
  @dataclass
31
31
  class GraphQLField:
32
32
  name: str
33
- alias: Optional[str]
33
+ alias: str | None
34
34
  type: GraphQLType
35
- default_value: Optional[GraphQLArgumentValue] = None
35
+ default_value: GraphQLArgumentValue | None = None
36
36
 
37
37
 
38
38
  @dataclass
@@ -44,7 +44,7 @@ class GraphQLFragmentSpread:
44
44
  class GraphQLObjectType:
45
45
  name: str
46
46
  fields: list[GraphQLField] = field(default_factory=list)
47
- graphql_typename: Optional[str] = None
47
+ graphql_typename: str | None = None
48
48
 
49
49
 
50
50
  # Subtype of GraphQLObjectType.
@@ -54,7 +54,7 @@ class GraphQLObjectType:
54
54
  class GraphQLFragmentType(GraphQLObjectType):
55
55
  name: str
56
56
  fields: list[GraphQLField] = field(default_factory=list)
57
- graphql_typename: Optional[str] = None
57
+ graphql_typename: str | None = None
58
58
  on: str = ""
59
59
 
60
60
  def __post_init__(self) -> None:
@@ -74,23 +74,23 @@ class GraphQLEnum:
74
74
  @dataclass
75
75
  class GraphQLScalar:
76
76
  name: str
77
- python_type: Optional[type]
77
+ python_type: type | None
78
78
 
79
79
 
80
- GraphQLType = Union[
81
- GraphQLObjectType,
82
- GraphQLEnum,
83
- GraphQLScalar,
84
- GraphQLOptional,
85
- GraphQLList,
86
- GraphQLUnion,
87
- ]
80
+ GraphQLType: TypeAlias = (
81
+ GraphQLObjectType
82
+ | GraphQLEnum
83
+ | GraphQLScalar
84
+ | GraphQLOptional
85
+ | GraphQLList
86
+ | GraphQLUnion
87
+ )
88
88
 
89
89
 
90
90
  @dataclass
91
91
  class GraphQLFieldSelection:
92
92
  field: str
93
- alias: Optional[str]
93
+ alias: str | None
94
94
  selections: list[GraphQLSelection]
95
95
  directives: list[GraphQLDirective]
96
96
  arguments: list[GraphQLArgument]
@@ -102,9 +102,9 @@ class GraphQLInlineFragment:
102
102
  selections: list[GraphQLSelection]
103
103
 
104
104
 
105
- GraphQLSelection = Union[
106
- GraphQLFieldSelection, GraphQLInlineFragment, GraphQLFragmentSpread
107
- ]
105
+ GraphQLSelection: TypeAlias = (
106
+ GraphQLFieldSelection | GraphQLInlineFragment | GraphQLFragmentSpread
107
+ )
108
108
 
109
109
 
110
110
  @dataclass
@@ -125,7 +125,7 @@ class GraphQLFloatValue:
125
125
  @dataclass
126
126
  class GraphQLEnumValue:
127
127
  name: str
128
- enum_type: Optional[str] = None
128
+ enum_type: str | None = None
129
129
 
130
130
 
131
131
  @dataclass
@@ -155,17 +155,17 @@ class GraphQLVariableReference:
155
155
  value: str
156
156
 
157
157
 
158
- GraphQLArgumentValue = Union[
159
- GraphQLStringValue,
160
- GraphQLNullValue,
161
- GraphQLIntValue,
162
- GraphQLVariableReference,
163
- GraphQLFloatValue,
164
- GraphQLListValue,
165
- GraphQLEnumValue,
166
- GraphQLBoolValue,
167
- GraphQLObjectValue,
168
- ]
158
+ GraphQLArgumentValue: TypeAlias = (
159
+ GraphQLStringValue
160
+ | GraphQLNullValue
161
+ | GraphQLIntValue
162
+ | GraphQLVariableReference
163
+ | GraphQLFloatValue
164
+ | GraphQLListValue
165
+ | GraphQLEnumValue
166
+ | GraphQLBoolValue
167
+ | GraphQLObjectValue
168
+ )
169
169
 
170
170
 
171
171
  @dataclass
@@ -194,7 +194,7 @@ class GraphQLOperation:
194
194
  directives: list[GraphQLDirective]
195
195
  variables: list[GraphQLVariable]
196
196
  type: GraphQLObjectType
197
- variables_type: Optional[GraphQLObjectType]
197
+ variables_type: GraphQLObjectType | None
198
198
 
199
199
 
200
200
  __all__ = [
@@ -0,0 +1,9 @@
1
+ from .annotated_unions import ConvertUnionToAnnotatedUnion
2
+ from .maybe_optional import ConvertMaybeToOptional
3
+ from .update_imports import UpdateImportsCodemod
4
+
5
+ __all__ = [
6
+ "ConvertMaybeToOptional",
7
+ "ConvertUnionToAnnotatedUnion",
8
+ "UpdateImportsCodemod",
9
+ ]
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import TYPE_CHECKING, Optional
3
+ from typing import TYPE_CHECKING
4
4
 
5
5
  import libcst as cst
6
6
  import libcst.matchers as m
@@ -50,7 +50,7 @@ class ConvertUnionToAnnotatedUnion(VisitorBasedCodemodCommand):
50
50
 
51
51
  super().__init__(context)
52
52
 
53
- def visit_Module(self, node: cst.Module) -> Optional[bool]: # noqa: N802
53
+ def visit_Module(self, node: cst.Module) -> bool | None: # noqa: N802
54
54
  self._is_using_named_import = False
55
55
 
56
56
  return super().visit_Module(node)