22
33from ..error import GraphQLError
44from ..language import DocumentNode , ParallelVisitor , visit
5- from ..pyutils import is_collection
5+ from ..pyutils import inspect , is_collection
66from ..type import GraphQLSchema , assert_valid_schema
77from ..utilities import TypeInfo , TypeInfoVisitor
88from .rules import ASTValidationRule
@@ -22,6 +22,7 @@ def validate(
2222 document_ast : DocumentNode ,
2323 rules : Optional [Collection [Type [ASTValidationRule ]]] = None ,
2424 max_errors : Optional [int ] = None ,
25+ type_info : Optional [TypeInfo ] = None ,
2526) -> List [GraphQLError ]:
2627 """Implements the "Validation" section of the spec.
2728
@@ -38,6 +39,8 @@ def validate(
3839 Validate will stop validation after a ``max_errors`` limit has been reached.
3940 Attackers can send pathologically invalid queries to induce a DoS attack,
4041 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.
4144 """
4245 if not document_ast or not isinstance (document_ast , DocumentNode ):
4346 raise TypeError ("Must provide document." )
@@ -47,6 +50,10 @@ def validate(
4750 max_errors = 100
4851 elif not isinstance (max_errors , int ):
4952 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 )} ." )
5057 if rules is None :
5158 rules = specified_rules
5259 elif not is_collection (rules ) or not all (
@@ -69,7 +76,6 @@ def on_error(error: GraphQLError) -> None:
6976 raise ValidationAbortedError
7077 errors .append (error )
7178
72- type_info = TypeInfo (schema )
7379 context = ValidationContext (schema , document_ast , type_info , on_error )
7480
7581 # This uses a specialized visitor which runs multiple visitors in parallel,
0 commit comments