2
2
3
3
from ..error import GraphQLError
4
4
from ..language import DocumentNode , ParallelVisitor , visit
5
- from ..pyutils import is_collection
5
+ from ..pyutils import inspect , is_collection
6
6
from ..type import GraphQLSchema , assert_valid_schema
7
7
from ..utilities import TypeInfo , TypeInfoVisitor
8
8
from .rules import ASTValidationRule
@@ -22,6 +22,7 @@ def validate(
22
22
document_ast : DocumentNode ,
23
23
rules : Optional [Collection [Type [ASTValidationRule ]]] = None ,
24
24
max_errors : Optional [int ] = None ,
25
+ type_info : Optional [TypeInfo ] = None ,
25
26
) -> List [GraphQLError ]:
26
27
"""Implements the "Validation" section of the spec.
27
28
@@ -38,6 +39,8 @@ def validate(
38
39
Validate will stop validation after a ``max_errors`` limit has been reached.
39
40
Attackers can send pathologically invalid queries to induce a DoS attack,
40
41
so by default ``max_errors`` set to 100 errors.
42
+
43
+ Providing a custom TypeInfo instance is deprecated and will be removed in v3.3.
41
44
"""
42
45
if not document_ast or not isinstance (document_ast , DocumentNode ):
43
46
raise TypeError ("Must provide document." )
@@ -47,6 +50,10 @@ def validate(
47
50
max_errors = 100
48
51
elif not isinstance (max_errors , int ):
49
52
raise TypeError ("The maximum number of errors must be passed as an int." )
53
+ if type_info is None :
54
+ type_info = TypeInfo (schema )
55
+ elif not isinstance (type_info , TypeInfo ):
56
+ raise TypeError (f"Not a TypeInfo object: { inspect (type_info )} ." )
50
57
if rules is None :
51
58
rules = specified_rules
52
59
elif not is_collection (rules ) or not all (
@@ -69,7 +76,6 @@ def on_error(error: GraphQLError) -> None:
69
76
raise ValidationAbortedError
70
77
errors .append (error )
71
78
72
- type_info = TypeInfo (schema )
73
79
context = ValidationContext (schema , document_ast , type_info , on_error )
74
80
75
81
# This uses a specialized visitor which runs multiple visitors in parallel,
0 commit comments