Ask Your Question
4

What is the method to restrict the depth of queries in strawberry-graphql when using Django implementation?

asked 2021-07-16 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-02-20 15:00:00 +0000

plato gravatar image

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.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2021-07-16 11:00:00 +0000

Seen: 11 times

Last updated: Feb 20 '23