strawberry.extensions.QueryDepthLimiter

Add a validator to limit the query depth of GraphQL operations.

Example:

import strawberry
from strawberry.extensions import QueryDepthLimiter
schema = strawberry.Schema(
Query,
extensions=[QueryDepthLimiter(max_depth=4)],
)

Constructor:

Initialize the QueryDepthLimiter.

Signature:

def __init__(
self,
max_depth: int,
callback: Callable[[Dict[str, int]], None] | None = None,
should_ignore: ShouldIgnoreType | None = None,
) -> None:
...

Parameters:

  1. max_depth:

    The maximum allowed depth for any operation in a GraphQL document.

    Type
    int
  2. callback:

    Called each time validation runs. Receives an Object which is a map of the depths for each operation.

    Type
    Callable[[Dict[str, int]], None] | None
    Default
    None
  3. should_ignore:

    Stops recursive depth checking based on a field name and arguments. A function that returns a boolean and conforms to the ShouldIgnoreType function signature.

    Type
    ShouldIgnoreType | None
    Default
    None