Open zerolab opened 10 months ago
Graphene now includes optional, configurable validation for this, so I don't think we need to do anything within grapple.
To limit query depth, you can append the rule to a custom GraphQLView
, e.g.:
from typing import List
import graphql
from django.conf import settings
from graphene import validation as graphene_validation
from graphene_django import views as graphene_django_views
from graphql.error import graphql_error
from graphql.language import ast
class CustomGraphQLView(graphene_django_views.GraphQLView):
...
def validate_query(self, document_ast: ast.DocumentNode) -> List[graphql_error.GraphQLError]:
return graphql.validate(
schema=self.schema.graphql_schema,
document_ast=document_ast,
rules=[
graphene_validation.depth_limit_validator(
max_depth=settings.MAX_GRAPHQL_QUERY_DEPTH
),
],
)
@kbayliss that's neat. Updated the issue to reflect that this is now a documentation issue. IMHO we want to document this as not everyone will scour the graphene docs
Refs:
325 could help with some of the nesting for pages