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
@@ -16,20 +16,19 @@ from typing import (
16
16
  )
17
17
  from typing_extensions import dataclass_transform
18
18
 
19
- from .exceptions import (
19
+ from strawberry.exceptions import (
20
20
  MissingFieldAnnotationError,
21
21
  MissingReturnAnnotationError,
22
22
  ObjectIsNotClassError,
23
23
  )
24
+ from strawberry.types.base import get_object_definition
25
+ from strawberry.utils.dataclasses import add_custom_init_fn
26
+ from strawberry.utils.deprecations import DEPRECATION_MESSAGES, DeprecatedDescriptor
27
+ from strawberry.utils.str_converters import to_camel_case
28
+
29
+ from .base import StrawberryObjectDefinition
24
30
  from .field import StrawberryField, field
25
- from .type import get_object_definition
26
- from .types.type_resolver import _get_fields
27
- from .types.types import (
28
- StrawberryObjectDefinition,
29
- )
30
- from .utils.dataclasses import add_custom_init_fn
31
- from .utils.deprecations import DEPRECATION_MESSAGES, DeprecatedDescriptor
32
- from .utils.str_converters import to_camel_case
31
+ from .type_resolver import _get_fields
33
32
 
34
33
  T = TypeVar("T", bound=Type)
35
34
 
@@ -103,9 +102,7 @@ def _check_field_annotations(cls: Type[Any]) -> None:
103
102
 
104
103
 
105
104
  def _wrap_dataclass(cls: Type[T]) -> Type[T]:
106
- """Wrap a strawberry.type class with a dataclass and check for any issues
107
- before doing so"""
108
-
105
+ """Wrap a strawberry.type class with a dataclass and check for any issues before doing so."""
109
106
  # Ensure all Fields have been properly type-annotated
110
107
  _check_field_annotations(cls)
111
108
 
@@ -232,11 +229,36 @@ def type(
232
229
  ) -> Union[T, Callable[[T], T]]:
233
230
  """Annotates a class as a GraphQL type.
234
231
 
232
+ Similar to `dataclasses.dataclass`, but with additional functionality for
233
+ defining GraphQL types.
234
+
235
+ Args:
236
+ cls: The class we want to create a GraphQL type from.
237
+ name: The name of the GraphQL type.
238
+ is_input: Whether the class is an input type. Used internally, use `@strawerry.input` instead of passing this flag.
239
+ is_interface: Whether the class is an interface. Used internally, use `@strawerry.interface` instead of passing this flag.
240
+ description: The description of the GraphQL type.
241
+ directives: The directives of the GraphQL type.
242
+ extend: Whether the class is extending an existing type.
243
+
244
+ Returns:
245
+ The class.
246
+
235
247
  Example usage:
236
248
 
237
- >>> @strawberry.type
238
- >>> class X:
239
- >>> field_abc: str = "ABC"
249
+ ```python
250
+ @strawberry.type
251
+ class User:
252
+ name: str = "A name"
253
+ ```
254
+
255
+ You can also pass parameters to the decorator:
256
+
257
+ ```python
258
+ @strawberry.type(name="UserType", description="A user type")
259
+ class MyUser:
260
+ name: str = "A name"
261
+ ```
240
262
  """
241
263
 
242
264
  def wrap(cls: T) -> T:
@@ -321,12 +343,35 @@ def input(
321
343
  directives: Optional[Sequence[object]] = (),
322
344
  ):
323
345
  """Annotates a class as a GraphQL Input type.
346
+
347
+ Similar to `@strawberry.type`, but for input types.
348
+
349
+ Args:
350
+ cls: The class we want to create a GraphQL input type from.
351
+ name: The name of the GraphQL input type.
352
+ description: The description of the GraphQL input type.
353
+ directives: The directives of the GraphQL input type.
354
+ one_of: Whether the input type is a `oneOf` type.
355
+
356
+ Returns:
357
+ The class.
358
+
324
359
  Example usage:
325
- >>> @strawberry.input
326
- >>> class X:
327
- >>> field_abc: str = "ABC"
328
- """
329
360
 
361
+ ```python
362
+ @strawberry.input
363
+ class UserInput:
364
+ name: str
365
+ ```
366
+
367
+ You can also pass parameters to the decorator:
368
+
369
+ ```python
370
+ @strawberry.input(name="UserInputType", description="A user input type")
371
+ class MyUserInput:
372
+ name: str
373
+ ```
374
+ """
330
375
  from strawberry.schema_directives import OneOf
331
376
 
332
377
  if one_of:
@@ -377,12 +422,34 @@ def interface(
377
422
  directives: Optional[Sequence[object]] = (),
378
423
  ):
379
424
  """Annotates a class as a GraphQL Interface.
425
+
426
+ Similar to `@strawberry.type`, but for interfaces.
427
+
428
+ Args:
429
+ cls: The class we want to create a GraphQL interface from.
430
+ name: The name of the GraphQL interface.
431
+ description: The description of the GraphQL interface.
432
+ directives: The directives of the GraphQL interface.
433
+
434
+ Returns:
435
+ The class.
436
+
380
437
  Example usage:
381
- >>> @strawberry.interface
382
- >>> class X:
383
- >>> field_abc: str
384
- """
385
438
 
439
+ ```python
440
+ @strawberry.interface
441
+ class Node:
442
+ id: str
443
+ ```
444
+
445
+ You can also pass parameters to the decorator:
446
+
447
+ ```python
448
+ @strawberry.interface(name="NodeType", description="A node type")
449
+ class MyNode:
450
+ id: str
451
+ ```
452
+ """
386
453
  return type( # type: ignore # not sure why mypy complains here
387
454
  cls,
388
455
  name=name,
@@ -394,15 +461,27 @@ def interface(
394
461
 
395
462
  def asdict(obj: Any) -> Dict[str, object]:
396
463
  """Convert a strawberry object into a dictionary.
464
+
397
465
  This wraps the dataclasses.asdict function to strawberry.
398
466
 
467
+ Args:
468
+ obj: The object to convert into a dictionary.
469
+
470
+ Returns:
471
+ A dictionary representation of the object.
472
+
399
473
  Example usage:
400
- >>> @strawberry.type
401
- >>> class User:
402
- >>> name: str
403
- >>> age: int
404
- >>> # should be {"name": "Lorem", "age": 25}
405
- >>> user_dict = strawberry.asdict(User(name="Lorem", age=25))
474
+
475
+ ```python
476
+ @strawberry.type
477
+ class User:
478
+ name: str
479
+ age: int
480
+
481
+
482
+ strawberry.asdict(User(name="Lorem", age=25))
483
+ # {"name": "Lorem", "age": 25}
484
+ ```
406
485
  """
407
486
  return dataclasses.asdict(obj)
408
487
 
@@ -10,17 +10,24 @@ class StrawberryPrivate: ...
10
10
  T = TypeVar("T")
11
11
 
12
12
  Private = Annotated[T, StrawberryPrivate()]
13
- Private.__doc__ = """Represents a field that won't be exposed in the GraphQL schema
13
+ """Represents a field that won't be exposed in the GraphQL schema.
14
14
 
15
15
  Example:
16
16
 
17
- >>> import strawberry
18
- >>> @strawberry.type
19
- ... class User:
20
- ... name: str
21
- ... age: strawberry.Private[int]
17
+ ```python
18
+ import strawberry
19
+
20
+
21
+ @strawberry.type
22
+ class User:
23
+ name: str
24
+ age: strawberry.Private[int]
25
+ ```
22
26
  """
23
27
 
24
28
 
25
29
  def is_private(type_: object) -> bool:
26
30
  return type_has_annotation(type_, StrawberryPrivate)
31
+
32
+
33
+ __all__ = ["Private", "is_private"]
@@ -16,9 +16,8 @@ from typing import (
16
16
  )
17
17
 
18
18
  from strawberry.exceptions import InvalidUnionTypeError
19
- from strawberry.type import StrawberryType
20
-
21
- from .utils.str_converters import to_camel_case
19
+ from strawberry.types.base import StrawberryType
20
+ from strawberry.utils.str_converters import to_camel_case
22
21
 
23
22
  if TYPE_CHECKING:
24
23
  from graphql import GraphQLScalarType
@@ -166,30 +165,44 @@ def scalar(
166
165
  ) -> Any:
167
166
  """Annotates a class or type as a GraphQL custom scalar.
168
167
 
168
+ Args:
169
+ cls: The class or type to annotate.
170
+ name: The GraphQL name of the scalar.
171
+ description: The description of the scalar.
172
+ specified_by_url: The URL of the specification.
173
+ serialize: The function to serialize the scalar.
174
+ parse_value: The function to parse the value.
175
+ parse_literal: The function to parse the literal.
176
+ directives: The directives to apply to the scalar.
177
+
178
+ Returns:
179
+ The decorated class or type.
180
+
169
181
  Example usages:
170
182
 
171
- >>> strawberry.scalar(
172
- >>> datetime.date,
173
- >>> serialize=lambda value: value.isoformat(),
174
- >>> parse_value=datetime.parse_date
175
- >>> )
176
-
177
- >>> Base64Encoded = strawberry.scalar(
178
- >>> NewType("Base64Encoded", bytes),
179
- >>> serialize=base64.b64encode,
180
- >>> parse_value=base64.b64decode
181
- >>> )
182
-
183
- >>> @strawberry.scalar(
184
- >>> serialize=lambda value: ",".join(value.items),
185
- >>> parse_value=lambda value: CustomList(value.split(","))
186
- >>> )
187
- >>> class CustomList:
188
- >>> def __init__(self, items):
189
- >>> self.items = items
183
+ ```python
184
+ strawberry.scalar(
185
+ datetime.date,
186
+ serialize=lambda value: value.isoformat(),
187
+ parse_value=datetime.parse_date,
188
+ )
190
189
 
191
- """
190
+ Base64Encoded = strawberry.scalar(
191
+ NewType("Base64Encoded", bytes),
192
+ serialize=base64.b64encode,
193
+ parse_value=base64.b64decode,
194
+ )
192
195
 
196
+
197
+ @strawberry.scalar(
198
+ serialize=lambda value: ",".join(value.items),
199
+ parse_value=lambda value: CustomList(value.split(",")),
200
+ )
201
+ class CustomList:
202
+ def __init__(self, items):
203
+ self.items = items
204
+ ```
205
+ """
193
206
  if parse_value is None:
194
207
  parse_value = cls
195
208
 
@@ -209,3 +222,6 @@ def scalar(
209
222
  return wrap
210
223
 
211
224
  return wrap(cls)
225
+
226
+
227
+ __all__ = ["ScalarDefinition", "ScalarWrapper", "scalar"]
@@ -10,16 +10,16 @@ from strawberry.exceptions import (
10
10
  FieldWithResolverAndDefaultValueError,
11
11
  PrivateStrawberryFieldError,
12
12
  )
13
- from strawberry.field import StrawberryField
14
- from strawberry.private import is_private
15
- from strawberry.type import has_object_definition
16
- from strawberry.unset import UNSET
13
+ from strawberry.types.base import has_object_definition
14
+ from strawberry.types.field import StrawberryField
15
+ from strawberry.types.private import is_private
16
+ from strawberry.types.unset import UNSET
17
17
 
18
18
 
19
19
  def _get_fields(
20
20
  cls: Type[Any], original_type_annotations: Dict[str, Type[Any]]
21
21
  ) -> List[StrawberryField]:
22
- """Get all the strawberry fields off a strawberry.type cls
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
25
25
  also paying attention the name and typing of the field.
@@ -27,16 +27,19 @@ def _get_fields(
27
27
  StrawberryFields can be defined on a strawberry.type class as either a dataclass-
28
28
  style field or using strawberry.field as a decorator.
29
29
 
30
- >>> import strawberry
31
- >>> @strawberry.type
32
- ... class Query:
33
- ... type_1a: int = 5
34
- ... type_1b: int = strawberry.field(...)
35
- ... type_1c: int = strawberry.field(resolver=...)
36
- ...
37
- ... @strawberry.field
38
- ... def type_2(self) -> int:
39
- ... ...
30
+ ```python
31
+ import strawberry
32
+
33
+
34
+ @strawberry.type
35
+ class Query:
36
+ type_1a: int = 5
37
+ type_1b: int = strawberry.field(...)
38
+ type_1c: int = strawberry.field(resolver=...)
39
+
40
+ @strawberry.field
41
+ def type_2(self) -> int: ...
42
+ ```
40
43
 
41
44
  Type #1:
42
45
  A pure dataclass-style field. Will not have a StrawberryField; one will need to
@@ -51,7 +54,6 @@ def _get_fields(
51
54
  passing a named function (i.e. not an anonymous lambda) to strawberry.field
52
55
  (typically as a decorator).
53
56
  """
54
-
55
57
  fields: Dict[str, StrawberryField] = {}
56
58
 
57
59
  # before trying to find any fields, let's first add the fields defined in
@@ -163,3 +165,6 @@ def _get_fields(
163
165
  fields[field_name] = field
164
166
 
165
167
  return list(fields.values())
168
+
169
+
170
+ __all__ = ["_get_fields"]
@@ -31,12 +31,12 @@ from strawberry.exceptions import (
31
31
  WrongReturnTypeForUnion,
32
32
  )
33
33
  from strawberry.exceptions.handler import should_use_rich_exceptions
34
- from strawberry.lazy_type import LazyType
35
- from strawberry.type import (
34
+ from strawberry.types.base import (
36
35
  StrawberryOptional,
37
36
  StrawberryType,
38
37
  has_object_definition,
39
38
  )
39
+ from strawberry.types.lazy_type import LazyType
40
40
 
41
41
  if TYPE_CHECKING:
42
42
  from graphql import (
@@ -173,7 +173,7 @@ class StrawberryUnion(StrawberryType):
173
173
  ) -> str:
174
174
  assert isinstance(type_, GraphQLUnionType)
175
175
 
176
- from strawberry.types.types import StrawberryObjectDefinition
176
+ from strawberry.types.base import StrawberryObjectDefinition
177
177
 
178
178
  # If the type given is not an Object type, try resolving using `is_type_of`
179
179
  # defined on the union's inner types
@@ -250,15 +250,27 @@ def union(
250
250
  ) -> StrawberryUnion:
251
251
  """Creates a new named Union type.
252
252
 
253
+ Args:
254
+ name: The GraphQL name of the Union type.
255
+ types: The types that the Union can be.
256
+ (Deprecated, use `Annotated[U, strawberry.union("Name")]` instead)
257
+ description: The GraphQL description of the Union type.
258
+ directives: The directives to attach to the Union type.
259
+
253
260
  Example usages:
254
261
 
255
- >>> @strawberry.type
256
- ... class A: ...
257
- >>> @strawberry.type
258
- ... class B: ...
259
- >>> Annotated[A | B, strawberry.union("Name")]
260
- """
262
+ ```python
263
+ import strawberry
264
+ from typing import Annotated
265
+
266
+ @strawberry.type
267
+ class A: ...
268
+
269
+ @strawberry.type
270
+ class B: ...
261
271
 
272
+ MyUnion = Annotated[A | B, strawberry.union("Name")]
273
+ """
262
274
  if types is None:
263
275
  union = StrawberryUnion(
264
276
  name=name,
@@ -299,3 +311,6 @@ def union(
299
311
  description=description,
300
312
  directives=directives,
301
313
  )
314
+
315
+
316
+ __all__ = ["StrawberryUnion", "union"]
@@ -28,6 +28,26 @@ class UnsetType:
28
28
 
29
29
 
30
30
  UNSET: Any = UnsetType()
31
+ """A special value that can be used to represent an unset value in a field or argument.
32
+ Similar to `undefined` in JavaScript, this value can be used to differentiate between
33
+ a field that was not set and a field that was set to `None` or `null`.
34
+
35
+ Example:
36
+
37
+ ```python
38
+ import strawberry
39
+
40
+
41
+ @strawberry.input
42
+ class UserInput:
43
+ name: str | None = strawberry.UNSET
44
+ age: int | None = strawberry.UNSET
45
+ ```
46
+
47
+ In the example above, if `name` or `age` are not provided when creating a `UserInput`
48
+ object, they will be set to `UNSET` instead of `None`. Use `is UNSET` to check
49
+ whether a value is unset.
50
+ """
31
51
 
32
52
 
33
53
  def _deprecated_is_unset(value: Any) -> bool:
strawberry/utils/aio.py CHANGED
@@ -67,3 +67,11 @@ async def resolve_awaitable(
67
67
  ) -> _R:
68
68
  """Resolves an awaitable object and calls a callback with the resolved value."""
69
69
  return callback(await awaitable)
70
+
71
+
72
+ __all__ = [
73
+ "aenumerate",
74
+ "aislice",
75
+ "asyncgen_to_list",
76
+ "resolve_awaitable",
77
+ ]
@@ -12,3 +12,6 @@ async def await_maybe(value: AwaitableOrValue[T]) -> T:
12
12
  return await value
13
13
 
14
14
  return cast(T, value)
15
+
16
+
17
+ __all__ = ["await_maybe", "AwaitableOrValue", "AsyncIteratorOrIterator"]
@@ -32,3 +32,6 @@ def add_custom_init_fn(cls: Any) -> None:
32
32
  globals_=globals_,
33
33
  ),
34
34
  )
35
+
36
+
37
+ __all__ = ["add_custom_init_fn"]
strawberry/utils/debug.py CHANGED
@@ -14,8 +14,8 @@ def pretty_print_graphql_operation(
14
14
  ) -> None:
15
15
  """Pretty print a GraphQL operation using pygments.
16
16
 
17
- Won't print introspection operation to prevent noise in the output."""
18
-
17
+ Won't print introspection operation to prevent noise in the output.
18
+ """
19
19
  try:
20
20
  from pygments import highlight, lexers
21
21
  from pygments.formatters import Terminal256Formatter
@@ -41,3 +41,6 @@ def pretty_print_graphql_operation(
41
41
  print( # noqa: T201
42
42
  highlight(variables_json, lexers.JsonLexer(), Terminal256Formatter())
43
43
  )
44
+
45
+
46
+ __all__ = ["pretty_print_graphql_operation"]
@@ -25,3 +25,6 @@ class DeprecatedDescriptor:
25
25
 
26
26
  def inject(self, klass: type) -> None:
27
27
  setattr(klass, self.attr_name, self)
28
+
29
+
30
+ __all__ = ["DEPRECATION_MESSAGES", "DeprecatedDescriptor"]
@@ -28,3 +28,6 @@ class GraphQLLexer(RegexLexer):
28
28
  (r"(\s|,)", token.Text),
29
29
  ]
30
30
  }
31
+
32
+
33
+ __all__ = ["GraphQLLexer"]
@@ -19,3 +19,6 @@ def import_module_symbol(
19
19
  symbol = getattr(symbol, attribute_name)
20
20
 
21
21
  return symbol
22
+
23
+
24
+ __all__ = ["import_module_symbol"]
@@ -12,7 +12,6 @@ from typing import (
12
12
  )
13
13
  from typing_extensions import get_args
14
14
 
15
- from strawberry.type import has_object_definition
16
15
  from strawberry.utils.typing import is_generic_alias
17
16
 
18
17
 
@@ -29,8 +28,7 @@ def in_async_context() -> bool:
29
28
 
30
29
  @lru_cache(maxsize=250)
31
30
  def get_func_args(func: Callable[[Any], Any]) -> List[str]:
32
- """Returns a list of arguments for the function"""
33
-
31
+ """Returns a list of arguments for the function."""
34
32
  sig = inspect.signature(func)
35
33
 
36
34
  return [
@@ -45,38 +43,46 @@ def get_specialized_type_var_map(cls: type) -> Optional[Dict[str, type]]:
45
43
 
46
44
  Consider the following:
47
45
 
48
- >>> class Foo(Generic[T]):
49
- ... ...
50
- ...
51
- >>> class Bar(Generic[K]):
52
- ... ...
53
- ...
54
- >>> class IntBar(Bar[int]):
55
- ... ...
56
- ...
57
- >>> class IntBarSubclass(IntBar):
58
- ... ...
59
- ...
60
- >>> class IntBarFoo(IntBar, Foo[str]):
61
- ... ...
62
- ...
46
+ ```python
47
+ class Foo(Generic[T]): ...
48
+
49
+
50
+ class Bar(Generic[K]): ...
51
+
52
+
53
+ class IntBar(Bar[int]): ...
54
+
55
+
56
+ class IntBarSubclass(IntBar): ...
57
+
58
+
59
+ class IntBarFoo(IntBar, Foo[str]): ...
60
+ ```
63
61
 
64
62
  This would return:
65
63
 
66
- >>> get_specialized_type_var_map(object)
67
- None
68
- >>> get_specialized_type_var_map(Foo)
69
- {}
70
- >>> get_specialized_type_var_map(Bar)
71
- {~T: ~T}
72
- >>> get_specialized_type_var_map(IntBar)
73
- {~T: int}
74
- >>> get_specialized_type_var_map(IntBarSubclass)
75
- {~T: int}
76
- >>> get_specialized_type_var_map(IntBarFoo)
77
- {~T: int, ~K: str}
64
+ ```python
65
+ get_specialized_type_var_map(object)
66
+ # None
67
+
68
+ get_specialized_type_var_map(Foo)
69
+ # {}
70
+
71
+ get_specialized_type_var_map(Bar)
72
+ # {~T: ~T}
73
+
74
+ get_specialized_type_var_map(IntBar)
75
+ # {~T: int}
78
76
 
77
+ get_specialized_type_var_map(IntBarSubclass)
78
+ # {~T: int}
79
+
80
+ get_specialized_type_var_map(IntBarFoo)
81
+ # {~T: int, ~K: str}
82
+ ```
79
83
  """
84
+ from strawberry.types.base import has_object_definition
85
+
80
86
  orig_bases = getattr(cls, "__orig_bases__", None)
81
87
  if orig_bases is None:
82
88
  # Specialized generic aliases will not have __orig_bases__
@@ -114,3 +120,6 @@ def get_specialized_type_var_map(cls: type) -> Optional[Dict[str, type]]:
114
120
  )
115
121
 
116
122
  return type_var_map
123
+
124
+
125
+ __all__ = ["in_async_context", "get_func_args", "get_specialized_type_var_map"]
@@ -23,3 +23,6 @@ class StrawberryLogger:
23
23
  **logger_kwargs: Any,
24
24
  ) -> None:
25
25
  cls.logger.error(error, exc_info=error.original_error, **logger_kwargs)
26
+
27
+
28
+ __all__ = ["StrawberryLogger"]
@@ -38,3 +38,6 @@ def get_operation_type(
38
38
  raise RuntimeError("Can't get GraphQL operation type")
39
39
 
40
40
  return OperationType(definition.operation.value)
41
+
42
+
43
+ __all__ = ["get_first_operation", "get_operation_type"]
@@ -24,3 +24,6 @@ def capitalize_first(name: str) -> str:
24
24
  def to_snake_case(name: str) -> str:
25
25
  name = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", name)
26
26
  return re.sub("([a-z0-9])([A-Z])", r"\1_\2", name).lower()
27
+
28
+
29
+ __all__ = ["to_camel_case", "to_kebab_case", "capitalize_first", "to_snake_case"]