Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the approach to limiting query depth #361

Open
zerolab opened this issue Sep 1, 2023 · 2 comments
Open

Document the approach to limiting query depth #361

zerolab opened this issue Sep 1, 2023 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@zerolab
Copy link
Member

zerolab commented Sep 1, 2023

Refs:

#325 could help with some of the nesting for pages

@kbayliss
Copy link
Collaborator

kbayliss commented Jan 12, 2024

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
                ),
            ],
        )

@zerolab zerolab changed the title Add option to limit query depth Document the approach to limiting query depth Jan 12, 2024
@zerolab zerolab added the documentation Improvements or additions to documentation label Jan 12, 2024
@zerolab
Copy link
Member Author

zerolab commented Jan 12, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants