-
Notifications
You must be signed in to change notification settings - Fork 768
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for validation rules (#1475)
* Add support for validation rules * Enable customizing validate max_errors through settings * Add tests for validation rules * Add examples for validation rules * Allow setting validation_rules in class def * Add tests for validation_rules inherited from parent class * Make tests for validation rules stricter
- Loading branch information
Showing
7 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Query Validation | ||
================ | ||
|
||
Graphene-Django supports query validation by allowing passing a list of validation rules (subclasses of `ValidationRule <https://github.com/graphql-python/graphql-core/blob/v3.2.3/src/graphql/validation/rules/__init__.py>`_ from graphql-core) to the ``validation_rules`` option in ``GraphQLView``. | ||
|
||
.. code:: python | ||
from django.urls import path | ||
from graphene.validation import DisableIntrospection | ||
from graphene_django.views import GraphQLView | ||
urlpatterns = [ | ||
path("graphql", GraphQLView.as_view(validation_rules=(DisableIntrospection,))), | ||
] | ||
or | ||
|
||
.. code:: python | ||
from django.urls import path | ||
from graphene.validation import DisableIntrospection | ||
from graphene_django.views import GraphQLView | ||
class View(GraphQLView): | ||
validation_rules = (DisableIntrospection,) | ||
urlpatterns = [ | ||
path("graphql", View.as_view()), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django.urls import path | ||
|
||
from graphene.validation import DisableIntrospection | ||
|
||
from ..views import GraphQLView | ||
from .schema_view import schema | ||
|
||
|
||
class View(GraphQLView): | ||
schema = schema | ||
|
||
|
||
class NoIntrospectionView(View): | ||
validation_rules = (DisableIntrospection,) | ||
|
||
|
||
class NoIntrospectionViewInherited(NoIntrospectionView): | ||
pass | ||
|
||
|
||
urlpatterns = [ | ||
path("graphql/", View.as_view()), | ||
path("graphql/validation/", View.as_view(validation_rules=(DisableIntrospection,))), | ||
path("graphql/validation/alternative/", NoIntrospectionView.as_view()), | ||
path("graphql/validation/inherited/", NoIntrospectionViewInherited.as_view()), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters