From f88900017d7347c8aa3851ba8efe62481eaeb8a8 Mon Sep 17 00:00:00 2001 From: Kien Dang Date: Wed, 1 Nov 2023 10:30:24 +0800 Subject: [PATCH] Add support for validation rules --- graphene_django/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/graphene_django/views.py b/graphene_django/views.py index 9fc6172..2cb8827 100644 --- a/graphene_django/views.py +++ b/graphene_django/views.py @@ -96,6 +96,7 @@ class GraphQLView(View): batch = False subscription_path = None execution_context_class = None + validation_rules = None def __init__( self, @@ -107,6 +108,7 @@ class GraphQLView(View): batch=False, subscription_path=None, execution_context_class=None, + validation_rules=None, ): if not schema: schema = graphene_settings.SCHEMA @@ -135,6 +137,8 @@ class GraphQLView(View): ), "A Schema is required to be provided to GraphQLView." assert not all((graphiql, batch)), "Use either graphiql or batch processing" + self.validation_rules = validation_rules + # noinspection PyUnusedLocal def get_root_value(self, request): return self.root_value @@ -332,7 +336,7 @@ class GraphQLView(View): ) ) - validation_errors = validate(schema, document) + validation_errors = validate(schema, document, self.validation_rules) if validation_errors: return ExecutionResult(data=None, errors=validation_errors)