mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-07 22:03:12 +03:00
Add support for validation rules
This commit is contained in:
parent
e735f5dbdb
commit
f88900017d
|
@ -96,6 +96,7 @@ class GraphQLView(View):
|
||||||
batch = False
|
batch = False
|
||||||
subscription_path = None
|
subscription_path = None
|
||||||
execution_context_class = None
|
execution_context_class = None
|
||||||
|
validation_rules = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -107,6 +108,7 @@ class GraphQLView(View):
|
||||||
batch=False,
|
batch=False,
|
||||||
subscription_path=None,
|
subscription_path=None,
|
||||||
execution_context_class=None,
|
execution_context_class=None,
|
||||||
|
validation_rules=None,
|
||||||
):
|
):
|
||||||
if not schema:
|
if not schema:
|
||||||
schema = graphene_settings.SCHEMA
|
schema = graphene_settings.SCHEMA
|
||||||
|
@ -135,6 +137,8 @@ class GraphQLView(View):
|
||||||
), "A Schema is required to be provided to GraphQLView."
|
), "A Schema is required to be provided to GraphQLView."
|
||||||
assert not all((graphiql, batch)), "Use either graphiql or batch processing"
|
assert not all((graphiql, batch)), "Use either graphiql or batch processing"
|
||||||
|
|
||||||
|
self.validation_rules = validation_rules
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
def get_root_value(self, request):
|
def get_root_value(self, request):
|
||||||
return self.root_value
|
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:
|
if validation_errors:
|
||||||
return ExecutionResult(data=None, errors=validation_errors)
|
return ExecutionResult(data=None, errors=validation_errors)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user