File: disable_introspection.py

package info (click to toggle)
python-graphene 3.4.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,120 kB
  • sloc: python: 8,935; makefile: 214; sh: 18
file content (16 lines) | stat: -rw-r--r-- 539 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from graphql import GraphQLError
from graphql.language import FieldNode
from graphql.validation import ValidationRule

from ..utils.is_introspection_key import is_introspection_key


class DisableIntrospection(ValidationRule):
    def enter_field(self, node: FieldNode, *_args):
        field_name = node.name.value
        if is_introspection_key(field_name):
            self.report_error(
                GraphQLError(
                    f"Cannot query '{field_name}': introspection is disabled.", node
                )
            )