@@ -35,12 +35,20 @@ def validate(
3535 a ValidationContext (see the language/visitor API). Visitor methods are expected to
3636 return GraphQLErrors, or lists of GraphQLErrors when invalid.
3737
38+ Validate will stop validation after a ``max_errors`` limit has been reached.
39+ Attackers can send pathologically invalid queries to induce a DoS attack,
40+ so by default ``max_errors`` set to 100 errors.
41+
3842 Providing a custom TypeInfo instance is deprecated and will be removed in v3.3.
3943 """
4044 if not document_ast or not isinstance (document_ast , DocumentNode ):
4145 raise TypeError ("Must provide document." )
4246 # If the schema used for validation is invalid, throw an error.
4347 assert_valid_schema (schema )
48+ if max_errors is None :
49+ max_errors = 100
50+ elif not isinstance (max_errors , int ):
51+ raise TypeError ("The maximum number of errors must be passed as an int." )
4452 if type_info is None :
4553 type_info = TypeInfo (schema )
4654 elif not isinstance (type_info , TypeInfo ):
@@ -53,13 +61,11 @@ def validate(
5361 raise TypeError (
5462 "Rules must be specified as a collection of ASTValidationRule subclasses."
5563 )
56- if max_errors is not None and not isinstance (max_errors , int ):
57- raise TypeError ("The maximum number of errors must be passed as an int." )
5864
5965 errors : List [GraphQLError ] = []
6066
6167 def on_error (error : GraphQLError ) -> None :
62- if max_errors is not None and len (errors ) >= max_errors :
68+ if len (errors ) >= max_errors : # type: ignore
6369 errors .append (
6470 GraphQLError (
6571 "Too many validation errors, error limit reached."
0 commit comments