Skip to content

Commit aab6d50

Browse files
committed
Improve handling of ValidationAbortedError
Replicates graphql/graphql-js@5aadd61
1 parent 70df39d commit aab6d50

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/graphql/validation/validate.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212
__all__ = ["assert_valid_sdl", "assert_valid_sdl_extension", "validate", "validate_sdl"]
1313

1414

15-
class ValidationAbortedError(RuntimeError):
15+
class ValidationAbortedError(GraphQLError):
1616
"""Error when a validation has been aborted (error limit reached)."""
1717

1818

19+
validation_aborted_error = ValidationAbortedError(
20+
"Too many validation errors, error limit reached. Validation aborted."
21+
)
22+
23+
1924
def validate(
2025
schema: GraphQLSchema,
2126
document_ast: DocumentNode,
@@ -54,13 +59,7 @@ def validate(
5459

5560
def on_error(error: GraphQLError) -> None:
5661
if len(errors) >= max_errors: # type: ignore
57-
errors.append(
58-
GraphQLError(
59-
"Too many validation errors, error limit reached."
60-
" Validation aborted."
61-
)
62-
)
63-
raise ValidationAbortedError
62+
raise validation_aborted_error
6463
errors.append(error)
6564

6665
context = ValidationContext(schema, document_ast, type_info, on_error)
@@ -73,7 +72,7 @@ def on_error(error: GraphQLError) -> None:
7372
try:
7473
visit(document_ast, TypeInfoVisitor(type_info, ParallelVisitor(visitors)))
7574
except ValidationAbortedError:
76-
pass
75+
errors.append(validation_aborted_error)
7776
return errors
7877

7978

0 commit comments

Comments
 (0)