You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/execution/queryvalidation.rst
+37-4Lines changed: 37 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ queries. It takes in the following arguments.
16
16
- ``ignore`` Stops recursive depth checking based on a field name. Either a string or regexp to match the name, or a function that returns a boolean
17
17
- ``callback`` Called each time validation runs. Receives an Object which is a map of the depths for each operation.
18
18
19
-
Example
19
+
Usage
20
20
-------
21
21
22
22
Here is how you would implement depth-limiting on your schema.
@@ -33,7 +33,7 @@ Here is how you would implement depth-limiting on your schema.
33
33
34
34
schema = Schema(query=MyQuery)
35
35
36
-
#Queries which have a depth more than 20
36
+
#queries which have a depth more than 20
37
37
# will not be executed.
38
38
39
39
validation_errors = validate(
@@ -47,6 +47,39 @@ Here is how you would implement depth-limiting on your schema.
47
47
)
48
48
49
49
50
+
Disable Introspection
51
+
---------------------
52
+
the disable introspection validation rule ensures that your schema cannot be introspected.
53
+
This is a useful security measure in production environments.
54
+
55
+
Usage
56
+
-------
57
+
58
+
Here is how you would disable introspection for your schema.
59
+
60
+
.. code:: python
61
+
from graphql import validate, parse
62
+
from graphene import ObjectType, Schema, String
63
+
from graphene.validation import DisableIntrospection
64
+
65
+
66
+
classMyQuery(ObjectType):
67
+
name = String(required=True)
68
+
69
+
70
+
schema = Schema(query=MyQuery)
71
+
72
+
# introspection queries will not be executed.
73
+
74
+
validation_errors = validate(
75
+
schema=schema,
76
+
document_ast=parse('THE QUERY'),
77
+
rules=(
78
+
DisableIntrospection,
79
+
)
80
+
)
81
+
82
+
50
83
Implementing custom validators
51
84
------------------------------
52
85
All custom query validators should extend the `ValidationRule <https://github.com/graphql-python/graphql-core/blob/v3.0.5/src/graphql/validation/rules/__init__.py#L37>`_
@@ -56,7 +89,7 @@ perform validation, your validator class should define one or more of enter_* an
56
89
enter/leave items as well as details on function documentation, please see contents of the visitor module. To make
57
90
validation fail, you should call validator's report_error method with the instance of GraphQLError describing failure
58
91
reason. Here is an example query validator that visits field definitions in GraphQL query and fails query validation
59
-
if any of those fields are blacklisted fields:
92
+
if any of those fields are blacklisted:
60
93
61
94
.. code:: python
62
95
from graphql import GraphQLError
@@ -70,7 +103,7 @@ if any of those fields are blacklisted fields:
0 commit comments