QueryDepthLimiter
This extension adds a validator to limit the query depth of GraphQL operations.
Usage example:
API reference:
max_depth: int
The maximum allowed depth for any operation in a GraphQL document.
callback: Optional[Callable[[Dict[str, int]], None]
Called each time validation runs. Receives a dictionary which is a map of the depths for each operation.
should_ignore: Optional[Callable[[IgnoreContext], bool]]
Called at each field to determine whether the field should be ignored or not.
Must be implemented by the user and returns True
if the field should be
ignored and False
otherwise.
The IgnoreContext
class has the following attributes:
-
field_name
of typestr
: the name of the field to be compared against -
field_args
of typestrawberry.extensions.query_depth_limiter.FieldArgumentsType
: the arguments of the field to be compared against -
query
of typegraphql.language.Node
: the query string -
context
of typegraphql.validation.ValidationContext
: the context passed to the query
This argument is injected, regardless of name, by the QueryDepthLimiter
class
and should not be passed by the user.
Instead, the user should write business logic to determine whether a field
should be ignored or not by the attributes of the IgnoreContext
class.