The method to restrict the depth of queries in strawberry-graphql when using Django implementation is by using the "max_depth" parameter in the "Schema" class.
The "max_depth" parameter sets the maximum depth allowed for nested queries in the GraphQL schema, and any query that exceeds this depth will result in an error.
Here is an example of implementing "max_depth" in a strawberry-graphql schema:
from strawberry import Schema
class Query:
...
schema = Schema(query=Query, max_depth=3)
In this example, the "max_depth" parameter is set to 3, meaning that any query with nested levels deeper than 3 will result in an error.
Asked: 2021-07-16 11:00:00 +0000
Seen: 11 times
Last updated: Feb 20 '23