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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-07-16 11:00:00 +0000
Seen: 8 times
Last updated: Feb 20