@@ -35,12 +35,20 @@ def validate(
35
35
a ValidationContext (see the language/visitor API). Visitor methods are expected to
36
36
return GraphQLErrors, or lists of GraphQLErrors when invalid.
37
37
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
+
38
42
Providing a custom TypeInfo instance is deprecated and will be removed in v3.3.
39
43
"""
40
44
if not document_ast or not isinstance (document_ast , DocumentNode ):
41
45
raise TypeError ("Must provide document." )
42
46
# If the schema used for validation is invalid, throw an error.
43
47
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." )
44
52
if type_info is None :
45
53
type_info = TypeInfo (schema )
46
54
elif not isinstance (type_info , TypeInfo ):
@@ -53,13 +61,11 @@ def validate(
53
61
raise TypeError (
54
62
"Rules must be specified as a collection of ASTValidationRule subclasses."
55
63
)
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." )
58
64
59
65
errors : List [GraphQLError ] = []
60
66
61
67
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
63
69
errors .append (
64
70
GraphQLError (
65
71
"Too many validation errors, error limit reached."
0 commit comments