This extension adds a validator to limit the maximum number of tokens in a GraphQL document sent to the server.

Usage example:

import strawberry
from strawberry.extensions import MaxTokensLimiter
schema = strawberry.Schema(

With the above configuration, if a client sends a query with more than 1000 tokens, the server will respond with an error message.

API reference:

class MaxTokensLimiter(max_token_count): ...

max_token_count: int

The maximum allowed number of tokens in a GraphQL document.

The following things are counted as tokens:

Not counted:

Edit this page on GitHub