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
@@ -92,7 +92,7 @@ FALLBACK_VERSION = Decimal("0.800")
92
92
 
93
93
 
94
94
  class MypyVersion:
95
- """Stores the mypy version to be used by the plugin"""
95
+ """Stores the mypy version to be used by the plugin."""
96
96
 
97
97
  VERSION: Decimal
98
98
 
@@ -330,9 +330,11 @@ def add_static_method_to_class(
330
330
  return_type: Type,
331
331
  tvar_def: Optional[TypeVarType] = None,
332
332
  ) -> None:
333
- """Adds a static method
334
- Edited add_method_to_class to incorporate static method logic
335
- https://github.com/python/mypy/blob/9c05d3d19/mypy/plugins/common.py
333
+ """Adds a static method.
334
+
335
+ Edited `add_method_to_class` to incorporate static method logic
336
+
337
+ https://github.com/python/mypy/blob/9c05d3d19/mypy/plugins/common.py.
336
338
  """
337
339
  info = cls.info
338
340
 
@@ -555,22 +557,22 @@ class StrawberryPlugin(Plugin):
555
557
  return None
556
558
 
557
559
  def _is_strawberry_union(self, fullname: str) -> bool:
558
- return fullname == "strawberry.union.union" or fullname.endswith(
560
+ return fullname == "strawberry.types.union.union" or fullname.endswith(
559
561
  "strawberry.union"
560
562
  )
561
563
 
562
564
  def _is_strawberry_enum(self, fullname: str) -> bool:
563
- return fullname == "strawberry.enum.enum" or fullname.endswith(
565
+ return fullname == "strawberry.types.enum.enum" or fullname.endswith(
564
566
  "strawberry.enum"
565
567
  )
566
568
 
567
569
  def _is_strawberry_scalar(self, fullname: str) -> bool:
568
- return fullname == "strawberry.custom_scalar.scalar" or fullname.endswith(
570
+ return fullname == "strawberry.types.scalar.scalar" or fullname.endswith(
569
571
  "strawberry.scalar"
570
572
  )
571
573
 
572
574
  def _is_strawberry_lazy_type(self, fullname: str) -> bool:
573
- return fullname == "strawberry.lazy_type.LazyType"
575
+ return fullname == "strawberry.types.lazy_type.LazyType"
574
576
 
575
577
  def _is_strawberry_create_type(self, fullname: str) -> bool:
576
578
  # using endswith(.create_type) is not ideal as there might be
@@ -9,31 +9,32 @@ if TYPE_CHECKING:
9
9
 
10
10
 
11
11
  class AddValidationRules(SchemaExtension):
12
- """
13
- Add graphql-core validation rules
12
+ """Add graphql-core validation rules.
14
13
 
15
14
  Example:
16
-
17
- >>> import strawberry
18
- >>> from strawberry.extensions import AddValidationRules
19
- >>> from graphql import ValidationRule, GraphQLError
20
- >>>
21
- >>> class MyCustomRule(ValidationRule):
22
- ... def enter_field(self, node, *args) -> None:
23
- ... if node.name.value == "secret_field":
24
- ... self.report_error(
25
- ... GraphQLError("Can't query field 'secret_field'")
26
- ... )
27
- >>>
28
- >>> schema = strawberry.Schema(
29
- ... Query,
30
- ... extensions=[
31
- ... AddValidationRules([
32
- ... MyCustomRule,
33
- ... ]),
34
- ... ]
35
- ... )
36
-
15
+ ```python
16
+ import strawberry
17
+ from strawberry.extensions import AddValidationRules
18
+ from graphql import ValidationRule, GraphQLError
19
+
20
+
21
+ class MyCustomRule(ValidationRule):
22
+ def enter_field(self, node, *args) -> None:
23
+ if node.name.value == "secret_field":
24
+ self.report_error(GraphQLError("Can't query field 'secret_field'"))
25
+
26
+
27
+ schema = strawberry.Schema(
28
+ Query,
29
+ extensions=[
30
+ AddValidationRules(
31
+ [
32
+ MyCustomRule,
33
+ ]
34
+ ),
35
+ ],
36
+ )
37
+ ```
37
38
  """
38
39
 
39
40
  validation_rules: List[Type[ASTValidationRule]]
@@ -46,3 +47,6 @@ class AddValidationRules(SchemaExtension):
46
47
  self.execution_context.validation_rules + tuple(self.validation_rules)
47
48
  )
48
49
  yield
50
+
51
+
52
+ __all__ = ["AddValidationRules"]
@@ -27,25 +27,25 @@ class SchemaExtension:
27
27
  def on_operation( # type: ignore
28
28
  self,
29
29
  ) -> AsyncIteratorOrIterator[None]: # pragma: no cover
30
- """Called before and after a GraphQL operation (query / mutation) starts"""
30
+ """Called before and after a GraphQL operation (query / mutation) starts."""
31
31
  yield None
32
32
 
33
33
  def on_validate( # type: ignore
34
34
  self,
35
35
  ) -> AsyncIteratorOrIterator[None]: # pragma: no cover
36
- """Called before and after the validation step"""
36
+ """Called before and after the validation step."""
37
37
  yield None
38
38
 
39
39
  def on_parse( # type: ignore
40
40
  self,
41
41
  ) -> AsyncIteratorOrIterator[None]: # pragma: no cover
42
- """Called before and after the parsing step"""
42
+ """Called before and after the parsing step."""
43
43
  yield None
44
44
 
45
45
  def on_execute( # type: ignore
46
46
  self,
47
47
  ) -> AsyncIteratorOrIterator[None]: # pragma: no cover
48
- """Called before and after the execution step"""
48
+ """Called before and after the execution step."""
49
49
  yield None
50
50
 
51
51
  def resolve(
@@ -70,3 +70,5 @@ HOOK_METHODS: Set[str] = {
70
70
  SchemaExtension.on_parse.__name__,
71
71
  SchemaExtension.on_execute.__name__,
72
72
  }
73
+
74
+ __all__ = ["SchemaExtension", "Hook", "HOOK_METHODS", "LifecycleStep"]
@@ -11,8 +11,8 @@ if TYPE_CHECKING:
11
11
  from graphql import DirectiveNode, GraphQLResolveInfo
12
12
 
13
13
  from strawberry.directive import StrawberryDirective
14
- from strawberry.field import StrawberryField
15
14
  from strawberry.schema.schema import Schema
15
+ from strawberry.types.field import StrawberryField
16
16
  from strawberry.utils.await_maybe import AwaitableOrValue
17
17
 
18
18
 
@@ -85,3 +85,6 @@ def process_directive(
85
85
  if value_parameter:
86
86
  arguments[value_parameter.name] = value
87
87
  return strawberry_directive, arguments
88
+
89
+
90
+ __all__ = ["DirectivesExtension", "DirectivesExtensionSync"]
@@ -4,21 +4,21 @@ from strawberry.extensions.base_extension import SchemaExtension
4
4
 
5
5
 
6
6
  class DisableValidation(SchemaExtension):
7
- """
8
- Disable query validation
7
+ """Disable query validation.
9
8
 
10
9
  Example:
11
10
 
12
- >>> import strawberry
13
- >>> from strawberry.extensions import DisableValidation
14
- >>>
15
- >>> schema = strawberry.Schema(
16
- ... Query,
17
- ... extensions=[
18
- ... DisableValidation,
19
- ... ]
20
- ... )
21
-
11
+ ```python
12
+ import strawberry
13
+ from strawberry.extensions import DisableValidation
14
+
15
+ schema = strawberry.Schema(
16
+ Query,
17
+ extensions=[
18
+ DisableValidation,
19
+ ],
20
+ )
21
+ ```
22
22
  """
23
23
 
24
24
  def __init__(self) -> None:
@@ -29,3 +29,6 @@ class DisableValidation(SchemaExtension):
29
29
  def on_operation(self) -> Iterator[None]:
30
30
  self.execution_context.validation_rules = () # remove all validation_rules
31
31
  yield
32
+
33
+
34
+ __all__ = ["DisableValidation"]
@@ -7,8 +7,8 @@ from typing import TYPE_CHECKING, Any, Awaitable, Callable, Union
7
7
  if TYPE_CHECKING:
8
8
  from typing_extensions import TypeAlias
9
9
 
10
- from strawberry.field import StrawberryField
11
10
  from strawberry.types import Info
11
+ from strawberry.types.field import StrawberryField
12
12
 
13
13
 
14
14
  SyncExtensionResolver: TypeAlias = Callable[..., Any]
@@ -44,7 +44,9 @@ class FieldExtension:
44
44
 
45
45
  class SyncToAsyncExtension(FieldExtension):
46
46
  """Helper class for mixing async extensions with sync resolvers.
47
- Applied automatically"""
47
+
48
+ Applied automatically.
49
+ """
48
50
 
49
51
  async def resolve_async(
50
52
  self, next_: AsyncExtensionResolver, source: Any, info: Info, **kwargs: Any
@@ -67,11 +69,12 @@ def _get_async_resolvers(
67
69
  def build_field_extension_resolvers(
68
70
  field: StrawberryField,
69
71
  ) -> list[Union[SyncExtensionResolver, AsyncExtensionResolver]]:
70
- """
72
+ """Builds a list of resolvers for a field with extensions.
73
+
71
74
  Verifies that all of the field extensions for a given field support
72
75
  sync or async depending on the field resolver.
73
- Inserts a SyncToAsyncExtension to be able to
74
- use Async extensions on sync resolvers
76
+
77
+ Inserts a SyncToAsyncExtension to be able to use Async extensions on sync resolvers
75
78
  Throws a TypeError otherwise.
76
79
 
77
80
  Returns True if resolving should be async, False on sync resolving
@@ -151,3 +154,6 @@ def build_field_extension_resolvers(
151
154
  f"If possible try to change the execution order so that all sync-only "
152
155
  f"extensions are executed first."
153
156
  )
157
+
158
+
159
+ __all__ = ["FieldExtension"]
@@ -44,3 +44,6 @@ class MaskErrors(SchemaExtension):
44
44
  processed_errors.append(error)
45
45
 
46
46
  result.errors = processed_errors
47
+
48
+
49
+ __all__ = ["MaskErrors"]
@@ -13,36 +13,35 @@ from strawberry.extensions.add_validation_rules import AddValidationRules
13
13
 
14
14
 
15
15
  class MaxAliasesLimiter(AddValidationRules):
16
- """
17
- Add a validator to limit the number of aliases used.
16
+ """Add a validator to limit the number of aliases used.
18
17
 
19
18
  Example:
20
19
 
21
- >>> import strawberry
22
- >>> from strawberry.extensions import MaxAliasesLimiter
23
- >>>
24
- >>> schema = strawberry.Schema(
25
- ... Query,
26
- ... extensions=[
27
- ... MaxAliasesLimiter(max_alias_count=15)
28
- ... ]
29
- ... )
30
-
31
- Arguments:
20
+ ```python
21
+ import strawberry
22
+ from strawberry.extensions import MaxAliasesLimiter
32
23
 
33
- `max_alias_count: int`
34
- The maximum number of aliases allowed in a GraphQL document.
24
+ schema = strawberry.Schema(Query, extensions=[MaxAliasesLimiter(max_alias_count=15)])
25
+ ```
35
26
  """
36
27
 
37
- def __init__(
38
- self,
39
- max_alias_count: int,
40
- ) -> None:
28
+ def __init__(self, max_alias_count: int) -> None:
29
+ """Initialize the MaxAliasesLimiter.
30
+
31
+ Args:
32
+ max_alias_count: The maximum number of aliases allowed in a GraphQL document.
33
+ """
41
34
  validator = create_validator(max_alias_count)
42
35
  super().__init__([validator])
43
36
 
44
37
 
45
38
  def create_validator(max_alias_count: int) -> Type[ValidationRule]:
39
+ """Create a validator that checks the number of aliases in a document.
40
+
41
+ Args:
42
+ max_alias_count: The maximum number of aliases allowed in a GraphQL document.
43
+ """
44
+
46
45
  class MaxAliasesValidator(ValidationRule):
47
46
  def __init__(self, validation_context: ValidationContext) -> None:
48
47
  document = validation_context.document
@@ -82,3 +81,6 @@ def count_fields_with_alias(
82
81
  result += count_fields_with_alias(selection)
83
82
 
84
83
  return result
84
+
85
+
86
+ __all__ = ["MaxAliasesLimiter"]
@@ -4,25 +4,15 @@ from strawberry.extensions.base_extension import SchemaExtension
4
4
 
5
5
 
6
6
  class MaxTokensLimiter(SchemaExtension):
7
- """
8
- Add a validator to limit the number of tokens in a GraphQL document.
7
+ """Add a validator to limit the number of tokens in a GraphQL document.
9
8
 
10
9
  Example:
10
+ ```python
11
+ import strawberry
12
+ from strawberry.extensions import MaxTokensLimiter
11
13
 
12
- >>> import strawberry
13
- >>> from strawberry.extensions import MaxTokensLimiter
14
- >>>
15
- >>> schema = strawberry.Schema(
16
- ... Query,
17
- ... extensions=[
18
- ... MaxTokensLimiter(max_token_count=1000)
19
- ... ]
20
- ... )
21
-
22
- Arguments:
23
-
24
- `max_token_count: int`
25
- The maximum number of tokens allowed in a GraphQL document.
14
+ schema = strawberry.Schema(Query, extensions=[MaxTokensLimiter(max_token_count=1000)])
15
+ ```
26
16
 
27
17
  The following things are counted as tokens:
28
18
  * various brackets: "{", "}", "(", ")"
@@ -37,8 +27,16 @@ class MaxTokensLimiter(SchemaExtension):
37
27
  self,
38
28
  max_token_count: int,
39
29
  ) -> None:
30
+ """Initialize the MaxTokensLimiter.
31
+
32
+ Args:
33
+ max_token_count: The maximum number of tokens allowed in a GraphQL document.
34
+ """
40
35
  self.max_token_count = max_token_count
41
36
 
42
37
  def on_operation(self) -> Iterator[None]:
43
38
  self.execution_context.parse_options["max_tokens"] = self.max_token_count
44
39
  yield
40
+
41
+
42
+ __all__ = ["MaxTokensLimiter"]
@@ -6,31 +6,31 @@ from strawberry.schema.execute import parse_document
6
6
 
7
7
 
8
8
  class ParserCache(SchemaExtension):
9
- """
10
- Add LRU caching the parsing step during execution to improve performance.
9
+ """Add LRU caching the parsing step during execution to improve performance.
11
10
 
12
11
  Example:
13
12
 
14
- >>> import strawberry
15
- >>> from strawberry.extensions import ParserCache
16
- >>>
17
- >>> schema = strawberry.Schema(
18
- ... Query,
19
- ... extensions=[
20
- ... ParserCache(maxsize=100),
21
- ... ]
22
- ... )
23
-
24
- Arguments:
25
-
26
- `maxsize: Optional[int]`
27
- Set the maxsize of the cache. If `maxsize` is set to `None` then the
28
- cache will grow without bound.
29
- More info: https://docs.python.org/3/library/functools.html#functools.lru_cache
30
-
13
+ ```python
14
+ import strawberry
15
+ from strawberry.extensions import ParserCache
16
+
17
+ schema = strawberry.Schema(
18
+ Query,
19
+ extensions=[
20
+ ParserCache(maxsize=100),
21
+ ],
22
+ )
23
+ ```
31
24
  """
32
25
 
33
26
  def __init__(self, maxsize: Optional[int] = None) -> None:
27
+ """Initialize the ParserCache.
28
+
29
+ Args:
30
+ maxsize: Set the maxsize of the cache. If `maxsize` is set to `None` then the
31
+ cache will grow without bound.
32
+ More info: https://docs.python.org/3/library/functools.html#functools.lru_cache
33
+ """
34
34
  self.cached_parse_document = lru_cache(maxsize=maxsize)(parse_document)
35
35
 
36
36
  def on_parse(self) -> Iterator[None]:
@@ -40,3 +40,6 @@ class ParserCache(SchemaExtension):
40
40
  execution_context.query, **execution_context.parse_options
41
41
  )
42
42
  yield
43
+
44
+
45
+ __all__ = ["ParserCache"]
@@ -9,9 +9,7 @@ from strawberry.extensions.base_extension import SchemaExtension
9
9
 
10
10
 
11
11
  class PyInstrument(SchemaExtension):
12
- """
13
- Extension to profile the execution time of resolvers using PyInstrument.
14
- """
12
+ """Extension to profile the execution time of resolvers using PyInstrument."""
15
13
 
16
14
  def __init__(
17
15
  self,
@@ -20,11 +18,6 @@ class PyInstrument(SchemaExtension):
20
18
  self._report_path = report_path
21
19
 
22
20
  def on_operation(self) -> Iterator[None]:
23
- """
24
- Called when an operation is started,
25
- in this case we start the profiler and yield
26
- then we stop the profiler when the operation is done
27
- """
28
21
  profiler = Profiler()
29
22
  profiler.start()
30
23
 
@@ -33,3 +26,6 @@ class PyInstrument(SchemaExtension):
33
26
  profiler.stop()
34
27
 
35
28
  Path(self._report_path, encoding="utf-8").write_text(profiler.output_html())
29
+
30
+
31
+ __all__ = ["PyInstrument"]
@@ -81,32 +81,19 @@ ShouldIgnoreType = Callable[[IgnoreContext], bool]
81
81
 
82
82
 
83
83
  class QueryDepthLimiter(AddValidationRules):
84
- """
85
- Add a validator to limit the query depth of GraphQL operations
84
+ """Add a validator to limit the query depth of GraphQL operations.
86
85
 
87
86
  Example:
88
87
 
89
- >>> import strawberry
90
- >>> from strawberry.extensions import QueryDepthLimiter
91
- >>>
92
- >>> schema = strawberry.Schema(
93
- ... Query,
94
- ... extensions=[
95
- ... QueryDepthLimiter(max_depth=4)
96
- ... ]
97
- ... )
98
-
99
- Arguments:
100
-
101
- `max_depth: int`
102
- The maximum allowed depth for any operation in a GraphQL document.
103
- `callback: Optional[Callable[[Dict[str, int]], None]`
104
- Called each time validation runs. Receives an Object which is a
105
- map of the depths for each operation.
106
- `should_ignore: Optional[ShouldIgnoreType]`
107
- Stops recursive depth checking based on a field name and arguments.
108
- A function that returns a boolean and conforms to the ShouldIgnoreType
109
- function signature.
88
+ ```python
89
+ import strawberry
90
+ from strawberry.extensions import QueryDepthLimiter
91
+
92
+ schema = strawberry.Schema(
93
+ Query,
94
+ extensions=[QueryDepthLimiter(max_depth=4)],
95
+ )
96
+ ```
110
97
  """
111
98
 
112
99
  def __init__(
@@ -115,6 +102,15 @@ class QueryDepthLimiter(AddValidationRules):
115
102
  callback: Optional[Callable[[Dict[str, int]], None]] = None,
116
103
  should_ignore: Optional[ShouldIgnoreType] = None,
117
104
  ) -> None:
105
+ """Initialize the QueryDepthLimiter.
106
+
107
+ Args:
108
+ max_depth: The maximum allowed depth for any operation in a GraphQL document.
109
+ callback: Called each time validation runs.
110
+ Receives an Object which is a map of the depths for each operation.
111
+ should_ignore: Stops recursive depth checking based on a field name and arguments.
112
+ A function that returns a boolean and conforms to the ShouldIgnoreType function signature.
113
+ """
118
114
  if should_ignore is not None and not callable(should_ignore):
119
115
  raise TypeError(
120
116
  "The `should_ignore` argument to "
@@ -317,3 +313,6 @@ def is_ignored(node: FieldNode, ignore: Optional[List[IgnoreType]] = None) -> bo
317
313
  raise TypeError(f"Invalid ignore option: {rule}")
318
314
 
319
315
  return False
316
+
317
+
318
+ __all__ = ["QueryDepthLimiter"]
@@ -84,3 +84,6 @@ class SchemaExtensionsRunner:
84
84
  middlewares = tuple(self.extensions) + additional_middlewares
85
85
 
86
86
  return MiddlewareManager(*middlewares)
87
+
88
+
89
+ __all__ = ["SchemaExtensionsRunner"]
@@ -191,3 +191,6 @@ class ApolloTracingExtensionSync(ApolloTracingExtension):
191
191
  end_timestamp = self.now()
192
192
  resolver_stats.duration = end_timestamp - start_timestamp
193
193
  self._resolver_stats.append(resolver_stats)
194
+
195
+
196
+ __all__ = ["ApolloTracingExtension", "ApolloTracingExtensionSync"]
@@ -43,18 +43,20 @@ class DatadogTracingExtension(SchemaExtension):
43
43
  name: str,
44
44
  **kwargs: Any,
45
45
  ) -> Span:
46
- """
47
- Create a span with the given name and kwargs.
46
+ """Create a span with the given name and kwargs.
47
+
48
48
  You can override this if you want to add more tags to the span.
49
49
 
50
50
  Example:
51
51
 
52
+ ```python
52
53
  class CustomExtension(DatadogTracingExtension):
53
54
  def create_span(self, lifecycle_step, name, **kwargs):
54
55
  span = super().create_span(lifecycle_step, name, **kwargs)
55
56
  if lifecycle_step == LifeCycleStep.OPERATION:
56
57
  span.set_tag("graphql.query", self.execution_context.query)
57
58
  return span
59
+ ```
58
60
  """
59
61
  return tracer.trace(
60
62
  name,
@@ -173,3 +175,6 @@ class DatadogTracingExtensionSync(DatadogTracingExtension):
173
175
  span.set_tag("graphql.path", ".".join(map(str, info.path.as_list())))
174
176
 
175
177
  return _next(root, info, *args, **kwargs)
178
+
179
+
180
+ __all__ = ["DatadogTracingExtension", "DatadogTracingExtensionSync"]
@@ -208,3 +208,6 @@ class OpenTelemetryExtensionSync(OpenTelemetryExtension):
208
208
  result = _next(root, info, *args, **kwargs)
209
209
 
210
210
  return result
211
+
212
+
213
+ __all__ = ["OpenTelemetryExtension", "OpenTelemetryExtensionSync"]
@@ -156,3 +156,6 @@ class SentryTracingExtensionSync(SentryTracingExtension):
156
156
  span.set_tag("graphql.path", ".".join(map(str, info.path.as_list())))
157
157
 
158
158
  return _next(root, info, *args, **kwargs)
159
+
160
+
161
+ __all__ = ["SentryTracingExtension", "SentryTracingExtensionSync"]
@@ -18,3 +18,6 @@ def should_skip_tracing(resolver: Callable[..., Any], info: GraphQLResolveInfo)
18
18
  or is_default_resolver(resolver)
19
19
  or resolver is None
20
20
  )
21
+
22
+
23
+ __all__ = ["should_skip_tracing"]
@@ -35,3 +35,6 @@ def get_path_from_info(info: GraphQLResolveInfo) -> List[str]:
35
35
  path = path.prev
36
36
 
37
37
  return elements[::-1]
38
+
39
+
40
+ __all__ = ["is_introspection_key", "is_introspection_field", "get_path_from_info"]
@@ -6,31 +6,31 @@ from strawberry.schema.execute import validate_document
6
6
 
7
7
 
8
8
  class ValidationCache(SchemaExtension):
9
- """
10
- Add LRU caching the validation step during execution to improve performance.
9
+ """Add LRU caching the validation step during execution to improve performance.
11
10
 
12
11
  Example:
13
-
14
- >>> import strawberry
15
- >>> from strawberry.extensions import ValidationCache
16
- >>>
17
- >>> schema = strawberry.Schema(
18
- ... Query,
19
- ... extensions=[
20
- ... ValidationCache(maxsize=100),
21
- ... ]
22
- ... )
23
-
24
- Arguments:
25
-
26
- `maxsize: Optional[int]`
27
- Set the maxsize of the cache. If `maxsize` is set to `None` then the
28
- cache will grow without bound.
29
- More info: https://docs.python.org/3/library/functools.html#functools.lru_cache
30
-
12
+ ```python
13
+ import strawberry
14
+ from strawberry.extensions import ValidationCache
15
+
16
+ schema = strawberry.Schema(
17
+ Query,
18
+ extensions=[
19
+ ValidationCache(maxsize=100),
20
+ ],
21
+ )
22
+ ```
31
23
  """
32
24
 
33
25
  def __init__(self, maxsize: Optional[int] = None) -> None:
26
+ """Initialize the ValidationCache.
27
+
28
+ Args:
29
+ maxsize: Set the maxsize of the cache. If `maxsize` is set to `None` then the
30
+ cache will grow without bound.
31
+
32
+ More info: https://docs.python.org/3/library/functools.html#functools.lru_cache
33
+ """
34
34
  self.cached_validate_document = lru_cache(maxsize=maxsize)(validate_document)
35
35
 
36
36
  def on_validate(self) -> Iterator[None]:
@@ -43,3 +43,6 @@ class ValidationCache(SchemaExtension):
43
43
  )
44
44
  execution_context.errors = errors
45
45
  yield
46
+
47
+
48
+ __all__ = ["ValidationCache"]
@@ -18,3 +18,6 @@ class BaseContext:
18
18
  self.request: Optional[Union[Request, WebSocket]] = None
19
19
  self.background_tasks: Optional[BackgroundTasks] = None
20
20
  self.response: Optional[Response] = None
21
+
22
+
23
+ __all__ = ["BaseContext"]