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.
Files changed (182) hide show
  1. strawberry/__init__.py +17 -11
  2. strawberry/aiohttp/handlers/graphql_transport_ws_handler.py +3 -0
  3. strawberry/aiohttp/handlers/graphql_ws_handler.py +3 -0
  4. strawberry/aiohttp/test/client.py +3 -0
  5. strawberry/aiohttp/views.py +3 -0
  6. strawberry/annotation.py +19 -22
  7. strawberry/asgi/__init__.py +3 -3
  8. strawberry/asgi/handlers/graphql_transport_ws_handler.py +3 -0
  9. strawberry/asgi/handlers/graphql_ws_handler.py +3 -0
  10. strawberry/asgi/test/client.py +3 -0
  11. strawberry/chalice/views.py +12 -3
  12. strawberry/channels/handlers/__init__.py +0 -0
  13. strawberry/channels/handlers/base.py +5 -5
  14. strawberry/channels/handlers/graphql_transport_ws_handler.py +3 -0
  15. strawberry/channels/handlers/graphql_ws_handler.py +3 -0
  16. strawberry/channels/handlers/http_handler.py +5 -2
  17. strawberry/channels/handlers/ws_handler.py +4 -1
  18. strawberry/channels/router.py +9 -5
  19. strawberry/channels/testing.py +11 -4
  20. strawberry/cli/commands/upgrade/__init__.py +13 -5
  21. strawberry/cli/commands/upgrade/_fake_progress.py +2 -1
  22. strawberry/cli/commands/upgrade/_run_codemod.py +18 -1
  23. strawberry/codegen/exceptions.py +8 -0
  24. strawberry/codegen/query_codegen.py +16 -7
  25. strawberry/codegen/types.py +32 -1
  26. strawberry/codemods/update_imports.py +136 -0
  27. strawberry/dataloader.py +13 -0
  28. strawberry/directive.py +52 -4
  29. strawberry/django/context.py +4 -1
  30. strawberry/django/test/client.py +3 -0
  31. strawberry/django/views.py +3 -0
  32. strawberry/exceptions/__init__.py +5 -5
  33. strawberry/exceptions/duplicated_type_name.py +1 -1
  34. strawberry/exceptions/invalid_argument_type.py +3 -3
  35. strawberry/exceptions/invalid_union_type.py +5 -6
  36. strawberry/exceptions/missing_arguments_annotations.py +1 -1
  37. strawberry/exceptions/missing_dependencies.py +10 -2
  38. strawberry/exceptions/missing_return_annotation.py +1 -1
  39. strawberry/exceptions/permission_fail_silently_requires_optional.py +3 -3
  40. strawberry/exceptions/scalar_already_registered.py +1 -1
  41. strawberry/exceptions/unresolved_field_type.py +2 -2
  42. strawberry/exceptions/utils/source_finder.py +5 -2
  43. strawberry/experimental/pydantic/conversion.py +5 -5
  44. strawberry/experimental/pydantic/conversion_types.py +4 -2
  45. strawberry/experimental/pydantic/error_type.py +2 -2
  46. strawberry/experimental/pydantic/fields.py +2 -2
  47. strawberry/experimental/pydantic/object_type.py +11 -7
  48. strawberry/experimental/pydantic/utils.py +4 -5
  49. strawberry/ext/dataclasses/dataclasses.py +2 -1
  50. strawberry/ext/mypy_plugin.py +10 -8
  51. strawberry/extensions/add_validation_rules.py +27 -23
  52. strawberry/extensions/base_extension.py +6 -4
  53. strawberry/extensions/directives.py +4 -1
  54. strawberry/extensions/disable_validation.py +15 -12
  55. strawberry/extensions/field_extension.py +11 -5
  56. strawberry/extensions/mask_errors.py +3 -0
  57. strawberry/extensions/max_aliases.py +21 -19
  58. strawberry/extensions/max_tokens.py +14 -16
  59. strawberry/extensions/parser_cache.py +22 -19
  60. strawberry/extensions/pyinstrument.py +4 -8
  61. strawberry/extensions/query_depth_limiter.py +22 -23
  62. strawberry/extensions/runner.py +3 -0
  63. strawberry/extensions/tracing/apollo.py +3 -0
  64. strawberry/extensions/tracing/datadog.py +7 -2
  65. strawberry/extensions/tracing/opentelemetry.py +3 -0
  66. strawberry/extensions/tracing/sentry.py +3 -0
  67. strawberry/extensions/tracing/utils.py +3 -0
  68. strawberry/extensions/utils.py +3 -0
  69. strawberry/extensions/validation_cache.py +23 -20
  70. strawberry/fastapi/context.py +3 -0
  71. strawberry/fastapi/handlers/graphql_transport_ws_handler.py +3 -0
  72. strawberry/fastapi/handlers/graphql_ws_handler.py +3 -0
  73. strawberry/fastapi/router.py +3 -0
  74. strawberry/federation/argument.py +4 -1
  75. strawberry/federation/enum.py +5 -3
  76. strawberry/federation/field.py +6 -3
  77. strawberry/federation/mutation.py +2 -0
  78. strawberry/federation/object_type.py +7 -4
  79. strawberry/federation/scalar.py +43 -20
  80. strawberry/federation/schema.py +12 -9
  81. strawberry/federation/schema_directive.py +2 -2
  82. strawberry/federation/schema_directives.py +19 -1
  83. strawberry/federation/types.py +5 -2
  84. strawberry/federation/union.py +27 -8
  85. strawberry/field_extensions/input_mutation.py +5 -2
  86. strawberry/file_uploads/scalars.py +3 -1
  87. strawberry/file_uploads/utils.py +3 -0
  88. strawberry/flask/views.py +8 -2
  89. strawberry/http/__init__.py +9 -0
  90. strawberry/http/async_base_view.py +4 -3
  91. strawberry/http/base.py +5 -7
  92. strawberry/http/exceptions.py +3 -0
  93. strawberry/http/ides.py +3 -0
  94. strawberry/http/sync_base_view.py +4 -3
  95. strawberry/http/temporal_response.py +3 -0
  96. strawberry/http/types.py +5 -2
  97. strawberry/http/typevars.py +3 -0
  98. strawberry/litestar/controller.py +6 -0
  99. strawberry/litestar/handlers/__init__.py +0 -0
  100. strawberry/litestar/handlers/graphql_transport_ws_handler.py +3 -0
  101. strawberry/litestar/handlers/graphql_ws_handler.py +3 -0
  102. strawberry/parent.py +27 -21
  103. strawberry/permission.py +70 -27
  104. strawberry/printer/ast_from_value.py +4 -1
  105. strawberry/printer/printer.py +8 -5
  106. strawberry/quart/views.py +3 -0
  107. strawberry/relay/exceptions.py +7 -0
  108. strawberry/relay/fields.py +70 -45
  109. strawberry/relay/types.py +78 -78
  110. strawberry/relay/utils.py +10 -1
  111. strawberry/resolvers.py +3 -0
  112. strawberry/sanic/context.py +3 -0
  113. strawberry/sanic/utils.py +10 -8
  114. strawberry/sanic/views.py +5 -9
  115. strawberry/scalars.py +6 -2
  116. strawberry/schema/base.py +7 -4
  117. strawberry/schema/compat.py +12 -2
  118. strawberry/schema/config.py +3 -0
  119. strawberry/schema/exceptions.py +3 -0
  120. strawberry/schema/execute.py +3 -0
  121. strawberry/schema/name_converter.py +12 -9
  122. strawberry/schema/schema.py +46 -9
  123. strawberry/schema/schema_converter.py +16 -14
  124. strawberry/schema/types/base_scalars.py +3 -1
  125. strawberry/schema/types/concrete_type.py +4 -4
  126. strawberry/schema/types/scalar.py +8 -1
  127. strawberry/schema/validation_rules/one_of.py +3 -0
  128. strawberry/schema_codegen/__init__.py +3 -0
  129. strawberry/schema_directive.py +2 -2
  130. strawberry/starlite/controller.py +3 -0
  131. strawberry/starlite/handlers/__init__.py +0 -0
  132. strawberry/starlite/handlers/graphql_transport_ws_handler.py +3 -0
  133. strawberry/starlite/handlers/graphql_ws_handler.py +3 -0
  134. strawberry/subscriptions/__init__.py +6 -0
  135. strawberry/subscriptions/protocols/graphql_transport_ws/__init__.py +5 -0
  136. strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py +12 -17
  137. strawberry/subscriptions/protocols/graphql_transport_ws/types.py +21 -25
  138. strawberry/subscriptions/protocols/graphql_ws/__init__.py +14 -0
  139. strawberry/subscriptions/protocols/graphql_ws/handlers.py +8 -5
  140. strawberry/subscriptions/protocols/graphql_ws/types.py +11 -0
  141. strawberry/test/client.py +44 -29
  142. strawberry/tools/create_type.py +27 -8
  143. strawberry/tools/merge_types.py +5 -3
  144. strawberry/types/__init__.py +8 -1
  145. strawberry/{arguments.py → types/arguments.py} +44 -13
  146. strawberry/{auto.py → types/auto.py} +21 -3
  147. strawberry/types/{types.py → base.py} +234 -10
  148. strawberry/{enum.py → types/enum.py} +69 -9
  149. strawberry/types/execution.py +3 -0
  150. strawberry/{field.py → types/field.py} +46 -23
  151. strawberry/types/fields/resolver.py +2 -2
  152. strawberry/types/graphql.py +3 -0
  153. strawberry/types/info.py +50 -7
  154. strawberry/{lazy_type.py → types/lazy_type.py} +50 -0
  155. strawberry/types/mutation.py +351 -0
  156. strawberry/types/nodes.py +4 -2
  157. strawberry/{object_type.py → types/object_type.py} +108 -29
  158. strawberry/{private.py → types/private.py} +13 -6
  159. strawberry/{custom_scalar.py → types/scalar.py} +39 -23
  160. strawberry/types/type_resolver.py +21 -16
  161. strawberry/{union.py → types/union.py} +24 -9
  162. strawberry/{unset.py → types/unset.py} +20 -0
  163. strawberry/utils/aio.py +8 -0
  164. strawberry/utils/await_maybe.py +3 -0
  165. strawberry/utils/dataclasses.py +3 -0
  166. strawberry/utils/debug.py +5 -2
  167. strawberry/utils/deprecations.py +3 -0
  168. strawberry/utils/graphql_lexer.py +3 -0
  169. strawberry/utils/importer.py +3 -0
  170. strawberry/utils/inspect.py +39 -30
  171. strawberry/utils/logging.py +3 -0
  172. strawberry/utils/operation.py +3 -0
  173. strawberry/utils/str_converters.py +3 -0
  174. strawberry/utils/typing.py +33 -16
  175. {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/METADATA +1 -1
  176. strawberry_graphql-0.236.0.dist-info/RECORD +255 -0
  177. strawberry/mutation.py +0 -8
  178. strawberry/type.py +0 -232
  179. strawberry_graphql-0.235.1.dev1719337273.dist-info/RECORD +0 -252
  180. {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/LICENSE +0 -0
  181. {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/WHEEL +0 -0
  182. {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/entry_points.txt +0 -0
@@ -15,3 +15,6 @@ class GraphQLTransportWSHandler(BaseGraphQLTransportWSHandler):
15
15
 
16
16
  async def get_root_value(self) -> Any:
17
17
  return await self._get_root_value()
18
+
19
+
20
+ __all__ = ["GraphQLTransportWSHandler"]
@@ -13,3 +13,6 @@ class GraphQLWSHandler(BaseGraphQLWSHandler):
13
13
 
14
14
  async def get_root_value(self) -> Any:
15
15
  return await self._get_root_value()
16
+
17
+
18
+ __all__ = ["GraphQLWSHandler"]
@@ -364,3 +364,6 @@ class GraphQLRouter(
364
364
  response.headers.raw.extend(sub_response.headers.raw)
365
365
 
366
366
  return response
367
+
368
+
369
+ __all__ = ["GraphQLRouter"]
@@ -1,6 +1,6 @@
1
1
  from typing import Iterable, Optional
2
2
 
3
- from strawberry.arguments import StrawberryArgumentAnnotation
3
+ from strawberry.types.arguments import StrawberryArgumentAnnotation
4
4
 
5
5
 
6
6
  def argument(
@@ -27,3 +27,6 @@ def argument(
27
27
  deprecation_reason=deprecation_reason,
28
28
  directives=directives,
29
29
  )
30
+
31
+
32
+ __all__ = ["argument"]
@@ -11,8 +11,8 @@ from typing import (
11
11
  overload,
12
12
  )
13
13
 
14
- from strawberry.enum import _process_enum
15
- from strawberry.enum import enum_value as base_enum_value
14
+ from strawberry.types.enum import _process_enum
15
+ from strawberry.types.enum import enum_value as base_enum_value
16
16
 
17
17
  if TYPE_CHECKING:
18
18
  from strawberry.enum import EnumType, EnumValueDefinition
@@ -85,7 +85,6 @@ def enum(
85
85
  If name is passed, the name of the GraphQL type will be
86
86
  the value passed of name instead of the Enum class name.
87
87
  """
88
-
89
88
  from strawberry.federation.schema_directives import (
90
89
  Authenticated,
91
90
  Inaccessible,
@@ -118,3 +117,6 @@ def enum(
118
117
  return wrap
119
118
 
120
119
  return wrap(_cls) # pragma: no cover
120
+
121
+
122
+ __all__ = ["enum", "enum_value"]
@@ -15,15 +15,15 @@ from typing import (
15
15
  overload,
16
16
  )
17
17
 
18
- from strawberry.field import field as base_field
19
- from strawberry.unset import UNSET
18
+ from strawberry.types.field import field as base_field
19
+ from strawberry.types.unset import UNSET
20
20
 
21
21
  if TYPE_CHECKING:
22
22
  from typing_extensions import Literal
23
23
 
24
24
  from strawberry.extensions.field_extension import FieldExtension
25
- from strawberry.field import _RESOLVER_TYPE, StrawberryField
26
25
  from strawberry.permission import BasePermission
26
+ from strawberry.types.field import _RESOLVER_TYPE, StrawberryField
27
27
 
28
28
  from .schema_directives import Override
29
29
 
@@ -203,3 +203,6 @@ def field(
203
203
  extensions=extensions,
204
204
  graphql_type=graphql_type,
205
205
  )
206
+
207
+
208
+ __all__ = ["field"]
@@ -1,3 +1,5 @@
1
1
  from .field import field
2
2
 
3
3
  mutation = field
4
+
5
+ __all__ = ["mutation"]
@@ -12,10 +12,10 @@ from typing import (
12
12
  )
13
13
  from typing_extensions import dataclass_transform
14
14
 
15
- from strawberry.field import StrawberryField
16
- from strawberry.field import field as base_field
17
- from strawberry.object_type import type as base_type
18
- from strawberry.unset import UNSET
15
+ from strawberry.types.field import StrawberryField
16
+ from strawberry.types.field import field as base_field
17
+ from strawberry.types.object_type import type as base_type
18
+ from strawberry.types.unset import UNSET
19
19
 
20
20
  from .field import field
21
21
 
@@ -369,3 +369,6 @@ def interface_object(
369
369
  is_interface=False,
370
370
  is_interface_object=True,
371
371
  )
372
+
373
+
374
+ __all__ = ["type", "input", "interface", "interface_object"]
@@ -11,7 +11,7 @@ from typing import (
11
11
  overload,
12
12
  )
13
13
 
14
- from strawberry.custom_scalar import ScalarWrapper, _process_scalar
14
+ from strawberry.types.scalar import ScalarWrapper, _process_scalar
15
15
 
16
16
  # in python 3.10+ NewType is a class
17
17
  if sys.version_info >= (3, 10):
@@ -79,28 +79,48 @@ def scalar(
79
79
  ) -> Any:
80
80
  """Annotates a class or type as a GraphQL custom scalar.
81
81
 
82
+ Args:
83
+ cls: The class or type to annotate
84
+ name: The GraphQL name of the scalar
85
+ description: The description of the scalar
86
+ specified_by_url: The URL of the specification
87
+ serialize: The function to serialize the scalar
88
+ parse_value: The function to parse the value
89
+ parse_literal: The function to parse the literal
90
+ directives: The directives to apply to the scalar
91
+ authenticated: Whether to add the @authenticated directive
92
+ inaccessible: Whether to add the @inaccessible directive
93
+ policy: The list of policy names to add to the @policy directive
94
+ requires_scopes: The list of scopes to add to the @requires directive
95
+ tags: The list of tags to add to the @tag directive
96
+
97
+ Returns:
98
+ The decorated class or type
99
+
82
100
  Example usages:
83
101
 
84
- >>> strawberry.federation.scalar(
85
- >>> datetime.date,
86
- >>> serialize=lambda value: value.isoformat(),
87
- >>> parse_value=datetime.parse_date
88
- >>> )
89
-
90
- >>> Base64Encoded = strawberry.federation.scalar(
91
- >>> NewType("Base64Encoded", bytes),
92
- >>> serialize=base64.b64encode,
93
- >>> parse_value=base64.b64decode
94
- >>> )
95
-
96
- >>> @strawberry.federation.scalar(
97
- >>> serialize=lambda value: ",".join(value.items),
98
- >>> parse_value=lambda value: CustomList(value.split(","))
99
- >>> )
100
- >>> class CustomList:
101
- >>> def __init__(self, items):
102
- >>> self.items = items
102
+ ```python
103
+ strawberry.federation.scalar(
104
+ datetime.date,
105
+ serialize=lambda value: value.isoformat(),
106
+ parse_value=datetime.parse_date,
107
+ )
108
+
109
+ Base64Encoded = strawberry.federation.scalar(
110
+ NewType("Base64Encoded", bytes),
111
+ serialize=base64.b64encode,
112
+ parse_value=base64.b64decode,
113
+ )
114
+
103
115
 
116
+ @strawberry.federation.scalar(
117
+ serialize=lambda value: ",".join(value.items),
118
+ parse_value=lambda value: CustomList(value.split(",")),
119
+ )
120
+ class CustomList:
121
+ def __init__(self, items):
122
+ self.items = items
123
+ ```
104
124
  """
105
125
  from strawberry.federation.schema_directives import (
106
126
  Authenticated,
@@ -146,3 +166,6 @@ def scalar(
146
166
  return wrap
147
167
 
148
168
  return wrap(cls)
169
+
170
+
171
+ __all__ = ["scalar"]
@@ -20,17 +20,17 @@ from typing import (
20
20
  from graphql import GraphQLError
21
21
 
22
22
  from strawberry.annotation import StrawberryAnnotation
23
- from strawberry.custom_scalar import scalar
24
23
  from strawberry.printer import print_schema
25
24
  from strawberry.schema import Schema as BaseSchema
26
- from strawberry.type import (
25
+ from strawberry.types.base import (
27
26
  StrawberryContainer,
27
+ StrawberryObjectDefinition,
28
28
  WithStrawberryObjectDefinition,
29
29
  get_object_definition,
30
30
  )
31
31
  from strawberry.types.info import Info
32
- from strawberry.types.types import StrawberryObjectDefinition
33
- from strawberry.union import StrawberryUnion
32
+ from strawberry.types.scalar import scalar
33
+ from strawberry.types.union import StrawberryUnion
34
34
  from strawberry.utils.inspect import get_func_args
35
35
 
36
36
  from .schema_directive import StrawberryFederationSchemaDirective
@@ -38,12 +38,12 @@ from .schema_directive import StrawberryFederationSchemaDirective
38
38
  if TYPE_CHECKING:
39
39
  from graphql import ExecutionContext as GraphQLExecutionContext
40
40
 
41
- from strawberry.custom_scalar import ScalarDefinition, ScalarWrapper
42
- from strawberry.enum import EnumDefinition
43
41
  from strawberry.extensions import SchemaExtension
44
42
  from strawberry.federation.schema_directives import ComposeDirective
45
43
  from strawberry.schema.config import StrawberryConfig
46
44
  from strawberry.schema_directive import StrawberrySchemaDirective
45
+ from strawberry.types.enum import EnumDefinition
46
+ from strawberry.types.scalar import ScalarDefinition, ScalarWrapper
47
47
 
48
48
 
49
49
  FederationAny = scalar(NewType("_Any", object), name="_Any") # type: ignore
@@ -112,7 +112,6 @@ class Schema(BaseSchema):
112
112
  The _service field is added by default, but the _entities field is only
113
113
  added if the schema contains an entity type.
114
114
  """
115
-
116
115
  import strawberry
117
116
  from strawberry.tools.create_type import create_type
118
117
  from strawberry.tools.merge_types import merge_types
@@ -181,7 +180,7 @@ class Schema(BaseSchema):
181
180
 
182
181
  get_result = partial(resolve_reference, **kwargs)
183
182
  else:
184
- from strawberry.arguments import convert_argument
183
+ from strawberry.types.arguments import convert_argument
185
184
 
186
185
  config = info.schema.config
187
186
  scalar_registry = info.schema.schema_converter.scalar_registry
@@ -209,7 +208,8 @@ class Schema(BaseSchema):
209
208
  def _remove_resolvable_field(self) -> None:
210
209
  # this might be removed when we remove support for federation 1
211
210
  # or when we improve how we print the directives
212
- from ..unset import UNSET
211
+ from strawberry.types.unset import UNSET
212
+
213
213
  from .schema_directives import Key
214
214
 
215
215
  for directive in self.schema_directives_in_use:
@@ -392,3 +392,6 @@ def _has_federation_keys(
392
392
  return any(_is_key(directive) for directive in definition.directives or [])
393
393
 
394
394
  return False
395
+
396
+
397
+ __all__ = ["Schema"]
@@ -3,9 +3,9 @@ from typing import Callable, List, Optional, Type, TypeVar
3
3
  from typing_extensions import dataclass_transform
4
4
 
5
5
  from strawberry.directive import directive_field
6
- from strawberry.field import StrawberryField, field
7
- from strawberry.object_type import _wrap_dataclass
8
6
  from strawberry.schema_directive import Location, StrawberrySchemaDirective
7
+ from strawberry.types.field import StrawberryField, field
8
+ from strawberry.types.object_type import _wrap_dataclass
9
9
  from strawberry.types.type_resolver import _get_fields
10
10
 
11
11
 
@@ -3,7 +3,7 @@ from typing import ClassVar, List, Optional
3
3
 
4
4
  from strawberry import directive_field
5
5
  from strawberry.schema_directive import Location, schema_directive
6
- from strawberry.unset import UNSET
6
+ from strawberry.types.unset import UNSET
7
7
 
8
8
  from .types import (
9
9
  FieldSet,
@@ -226,3 +226,21 @@ class Policy(FederationDirective):
226
226
  imported_from: ClassVar[ImportedFrom] = ImportedFrom(
227
227
  name="policy", url="https://specs.apollo.dev/federation/v2.7"
228
228
  )
229
+
230
+
231
+ __all__ = [
232
+ "External",
233
+ "Requires",
234
+ "Provides",
235
+ "Key",
236
+ "Shareable",
237
+ "Link",
238
+ "Tag",
239
+ "Override",
240
+ "Inaccessible",
241
+ "ComposeDirective",
242
+ "InterfaceObject",
243
+ "Authenticated",
244
+ "RequiresScopes",
245
+ "Policy",
246
+ ]
@@ -1,7 +1,7 @@
1
1
  from enum import Enum
2
2
 
3
- from strawberry.custom_scalar import scalar
4
- from strawberry.enum import enum
3
+ from strawberry.types.enum import enum
4
+ from strawberry.types.scalar import scalar
5
5
 
6
6
  FieldSet = scalar(str, name="_FieldSet")
7
7
 
@@ -12,3 +12,6 @@ LinkImport = scalar(object, name="link__Import")
12
12
  class LinkPurpose(Enum):
13
13
  SECURITY = "SECURITY"
14
14
  EXECUTION = "EXECUTION"
15
+
16
+
17
+ __all__ = ["FieldSet", "LinkImport", "LinkPurpose"]
@@ -1,7 +1,7 @@
1
1
  from typing import Any, Collection, Iterable, Optional, Type
2
2
 
3
- from strawberry.union import StrawberryUnion
4
- from strawberry.union import union as base_union
3
+ from strawberry.types.union import StrawberryUnion
4
+ from strawberry.types.union import union as base_union
5
5
 
6
6
 
7
7
  def union(
@@ -15,15 +15,31 @@ def union(
15
15
  ) -> StrawberryUnion:
16
16
  """Creates a new named Union type.
17
17
 
18
+ Args:
19
+ name: The GraphQL name of the Union type.
20
+ types: The types that the Union can be.
21
+ (Deprecated, use `Annotated[U, strawberry.federation.union("Name")]` instead)
22
+ description: The GraphQL description of the Union type.
23
+ directives: The directives to attach to the Union type.
24
+ inaccessible: Whether the Union type is inaccessible.
25
+ tags: The federation tags to attach to the Union type.
26
+
18
27
  Example usages:
19
28
 
20
- >>> @strawberry.type
21
- ... class A: ...
22
- >>> @strawberry.type
23
- ... class B: ...
24
- >>> strawberry.federation.union("Name", (A, Optional[B]))
25
- """
29
+ ```python
30
+ import strawberry
31
+ from typing import Annotated
32
+
33
+ @strawberry.federation.type(keys=["id"])
34
+ class A:
35
+ id: strawberry.ID
36
+
37
+ @strawberry.federation.type(keys=["id"])
38
+ class B:
39
+ id: strawberry.ID
26
40
 
41
+ MyUnion = Annotated[A | B, strawberry.federation.union("Name", tags=["tag"])]
42
+ """
27
43
  from strawberry.federation.schema_directives import Inaccessible, Tag
28
44
 
29
45
  directives = list(directives)
@@ -40,3 +56,6 @@ def union(
40
56
  description=description,
41
57
  directives=directives,
42
58
  )
59
+
60
+
61
+ __all__ = ["union"]
@@ -8,13 +8,13 @@ from typing import (
8
8
 
9
9
  import strawberry
10
10
  from strawberry.annotation import StrawberryAnnotation
11
- from strawberry.arguments import StrawberryArgument
12
11
  from strawberry.extensions.field_extension import (
13
12
  AsyncExtensionResolver,
14
13
  FieldExtension,
15
14
  SyncExtensionResolver,
16
15
  )
17
- from strawberry.field import StrawberryField
16
+ from strawberry.types.arguments import StrawberryArgument
17
+ from strawberry.types.field import StrawberryField
18
18
  from strawberry.utils.str_converters import capitalize_first, to_camel_case
19
19
 
20
20
  if TYPE_CHECKING:
@@ -90,3 +90,6 @@ class InputMutationExtension(FieldExtension):
90
90
  **kwargs,
91
91
  **vars(input_args),
92
92
  )
93
+
94
+
95
+ __all__ = ["InputMutationExtension"]
@@ -1,5 +1,7 @@
1
1
  from typing import NewType
2
2
 
3
- from ..custom_scalar import scalar
3
+ from strawberry.types.scalar import scalar
4
4
 
5
5
  Upload = scalar(NewType("Upload", bytes), parse_value=lambda x: x)
6
+
7
+ __all__ = ["Upload"]
@@ -30,3 +30,6 @@ def replace_placeholders_with_files(
30
30
  target_object[value_key] = file_object
31
31
 
32
32
  return operations
33
+
34
+
35
+ __all__ = ["replace_placeholders_with_files"]
strawberry/flask/views.py CHANGED
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import warnings
4
- from typing import TYPE_CHECKING, Any, List, Mapping, Optional, Union, cast
4
+ from typing import TYPE_CHECKING, Any, Mapping, Optional, Union, cast
5
5
 
6
6
  from flask import Request, Response, render_template_string, request
7
7
  from flask.views import View
@@ -26,7 +26,7 @@ class FlaskHTTPRequestAdapter(SyncHTTPRequestAdapter):
26
26
  self.request = request
27
27
 
28
28
  @property
29
- def query_params(self) -> Mapping[str, Union[str, Optional[List[str]]]]:
29
+ def query_params(self) -> QueryParams:
30
30
  return self.request.args.to_dict()
31
31
 
32
32
  @property
@@ -177,3 +177,9 @@ class AsyncGraphQLView(
177
177
 
178
178
  async def render_graphql_ide(self, request: Request) -> Response:
179
179
  return render_template_string(self.graphql_ide_html) # type: ignore
180
+
181
+
182
+ __all__ = [
183
+ "GraphQLView",
184
+ "AsyncGraphQLView",
185
+ ]
@@ -48,3 +48,12 @@ def parse_request_data(data: Mapping[str, Any]) -> GraphQLRequestData:
48
48
  variables=data.get("variables"),
49
49
  operation_name=data.get("operationName"),
50
50
  )
51
+
52
+
53
+ __all__ = [
54
+ "GraphQLHTTPResponse",
55
+ "process_result",
56
+ "GraphQLRequestData",
57
+ "parse_query_params",
58
+ "parse_request_data",
59
+ ]
@@ -136,9 +136,7 @@ class AsyncBaseHTTPView(
136
136
  def _handle_errors(
137
137
  self, errors: List[GraphQLError], response_data: GraphQLHTTPResponse
138
138
  ) -> None:
139
- """
140
- Hook to allow custom handling of errors, used by the Sentry Integration
141
- """
139
+ """Hook to allow custom handling of errors, used by the Sentry Integration."""
142
140
 
143
141
  async def run(
144
142
  self,
@@ -213,3 +211,6 @@ class AsyncBaseHTTPView(
213
211
  self, request: Request, result: ExecutionResult
214
212
  ) -> GraphQLHTTPResponse:
215
213
  return process_result(result)
214
+
215
+
216
+ __all__ = ["AsyncBaseHTTPView"]
strawberry/http/base.py CHANGED
@@ -4,7 +4,7 @@ from typing_extensions import Protocol
4
4
 
5
5
  from strawberry.http import GraphQLHTTPResponse
6
6
  from strawberry.http.ides import GraphQL_IDE, get_graphql_ide_html
7
- from strawberry.http.types import HTTPMethod
7
+ from strawberry.http.types import HTTPMethod, QueryParams
8
8
 
9
9
  from .exceptions import HTTPException
10
10
  from .typevars import Request
@@ -50,17 +50,12 @@ class BaseView(Generic[Request]):
50
50
  def encode_json(self, response_data: GraphQLHTTPResponse) -> str:
51
51
  return json.dumps(response_data)
52
52
 
53
- def parse_query_params(
54
- self, params: Mapping[str, Optional[Union[str, List[str]]]]
55
- ) -> Dict[str, Any]:
53
+ def parse_query_params(self, params: QueryParams) -> Dict[str, Any]:
56
54
  params = dict(params)
57
55
 
58
56
  if "variables" in params:
59
57
  variables = params["variables"]
60
58
 
61
- if isinstance(variables, list):
62
- variables = variables[0]
63
-
64
59
  if variables:
65
60
  params["variables"] = self.parse_json(variables)
66
61
 
@@ -73,3 +68,6 @@ class BaseView(Generic[Request]):
73
68
  replace_variables=self._ide_replace_variables,
74
69
  graphql_ide=self.graphql_ide,
75
70
  )
71
+
72
+
73
+ __all__ = ["BaseView"]
@@ -2,3 +2,6 @@ class HTTPException(Exception):
2
2
  def __init__(self, status_code: int, reason: str) -> None:
3
3
  self.status_code = status_code
4
4
  self.reason = reason
5
+
6
+
7
+ __all__ = ["HTTPException"]
strawberry/http/ides.py CHANGED
@@ -28,3 +28,6 @@ def get_graphql_ide_html(
28
28
  )
29
29
 
30
30
  return template
31
+
32
+
33
+ __all__ = ["get_graphql_ide_html", "GraphQL_IDE"]
@@ -151,9 +151,7 @@ class SyncBaseHTTPView(
151
151
  def _handle_errors(
152
152
  self, errors: List[GraphQLError], response_data: GraphQLHTTPResponse
153
153
  ) -> None:
154
- """
155
- Hook to allow custom handling of errors, used by the Sentry Integration
156
- """
154
+ """Hook to allow custom handling of errors, used by the Sentry Integration."""
157
155
 
158
156
  def run(
159
157
  self,
@@ -208,3 +206,6 @@ class SyncBaseHTTPView(
208
206
  self, request: Request, result: ExecutionResult
209
207
  ) -> GraphQLHTTPResponse:
210
208
  return process_result(result)
209
+
210
+
211
+ __all__ = ["SyncBaseHTTPView"]
@@ -6,3 +6,6 @@ from typing import Dict
6
6
  class TemporalResponse:
7
7
  status_code: int = 200
8
8
  headers: Dict[str, str] = field(default_factory=dict)
9
+
10
+
11
+ __all__ = ["TemporalResponse"]
strawberry/http/types.py CHANGED
@@ -1,13 +1,16 @@
1
- from typing import Any, List, Mapping, Optional, Union
1
+ from typing import Any, Mapping, Optional
2
2
  from typing_extensions import Literal, TypedDict
3
3
 
4
4
  HTTPMethod = Literal[
5
5
  "GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "TRACE"
6
6
  ]
7
7
 
8
- QueryParams = Mapping[str, Optional[Union[str, List[str]]]]
8
+ QueryParams = Mapping[str, Optional[str]]
9
9
 
10
10
 
11
11
  class FormData(TypedDict):
12
12
  files: Mapping[str, Any]
13
13
  form: Mapping[str, Any]
14
+
15
+
16
+ __all__ = ["HTTPMethod", "QueryParams", "FormData"]
@@ -5,3 +5,6 @@ Response = TypeVar("Response")
5
5
  SubResponse = TypeVar("SubResponse")
6
6
  Context = TypeVar("Context")
7
7
  RootValue = TypeVar("RootValue")
8
+
9
+
10
+ __all__ = ["Request", "Response", "SubResponse", "Context", "RootValue"]
@@ -433,3 +433,9 @@ def make_graphql_controller(
433
433
  _GraphQLController.graphql_ide = graphql_ide_
434
434
 
435
435
  return _GraphQLController
436
+
437
+
438
+ __all__ = [
439
+ "make_graphql_controller",
440
+ "GraphQLController",
441
+ ]
File without changes
@@ -55,3 +55,6 @@ class GraphQLTransportWSHandler(BaseGraphQLTransportWSHandler):
55
55
  pass
56
56
  finally:
57
57
  await self.shutdown()
58
+
59
+
60
+ __all__ = ["GraphQLTransportWSHandler"]
@@ -60,3 +60,6 @@ class GraphQLWSHandler(BaseGraphQLWSHandler):
60
60
 
61
61
  for operation_id in list(self.subscriptions.keys()):
62
62
  await self.cleanup_operation(operation_id)
63
+
64
+
65
+ __all__ = ["GraphQLWSHandler"]