Enable customizing validate max_errors through settings

This commit is contained in:
Kien Dang 2023-11-01 10:31:53 +08:00
parent f88900017d
commit 918b590eea
3 changed files with 18 additions and 1 deletions

View File

@ -269,3 +269,14 @@ Default: ``False``
.. _GraphiQLDocs: https://graphiql-test.netlify.app/typedoc/modules/graphiql_react#graphiqlprovider-2
``MAX_VALIDATION_ERRORS``
------------------------------------
In case ``validation_rules`` are provided to ``GraphQLView``, if this is set to a non-negative ``int`` value,
``graphql.validation.validate`` will stop validation after this number of errors has been reached.
If not set or set to ``None``, the maximum number of errors will follow ``graphql.validation.validate`` default
*i.e.* 100.
Default: ``None``

View File

@ -43,6 +43,7 @@ DEFAULTS = {
"GRAPHIQL_INPUT_VALUE_DEPRECATION": False,
"ATOMIC_MUTATIONS": False,
"TESTING_ENDPOINT": "/graphql",
"MAX_VALIDATION_ERRORS": None,
}
if settings.DEBUG:

View File

@ -336,7 +336,12 @@ class GraphQLView(View):
)
)
validation_errors = validate(schema, document, self.validation_rules)
validation_errors = validate(
schema,
document,
self.validation_rules,
graphene_settings.MAX_VALIDATION_ERRORS,
)
if validation_errors:
return ExecutionResult(data=None, errors=validation_errors)