diff --git a/.gitignore b/.gitignore index 642f015..bfac963 100644 --- a/.gitignore +++ b/.gitignore @@ -158,6 +158,9 @@ target/ # pyenv .python-version +# Pycharm venv +venv/ + # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. # However, in case of collaboration, if having platform-specific dependencies or dependencies diff --git a/docs/aiohttp.md b/docs/aiohttp.md index 35f7fbf..d65bcb8 100644 --- a/docs/aiohttp.md +++ b/docs/aiohttp.md @@ -59,6 +59,7 @@ gql_view(request) # <-- the instance is callable and expects a `aiohttp.web.Req `Template.render_async` instead of `Template.render`. If environment is not set, fallbacks to simple regex-based renderer. * `batch`: Set the GraphQL view as batch (for using in [Apollo-Client](http://dev.apollodata.com/core/network.html#query-batching) or [ReactRelayNetworkLayer](https://github.com/nodkz/react-relay-network-layer)) * `middleware`: A list of graphql [middlewares](http://docs.graphene-python.org/en/latest/execution/middleware/). + * `validation_rules`: A list of graphql validation rules. * `max_age`: Sets the response header Access-Control-Max-Age for preflight requests. * `encode`: the encoder to use for responses (sensibly defaults to `graphql_server.json_encode`). * `format_error`: the error formatter to use for responses (sensibly defaults to `graphql_server.default_format_error`. diff --git a/docs/flask.md b/docs/flask.md index 80bab4f..f3a36e7 100644 --- a/docs/flask.md +++ b/docs/flask.md @@ -58,6 +58,7 @@ More info at [Graphene v3 release notes](https://github.com/graphql-python/graph * `graphiql_html_title`: The graphiql title to display. Defaults to **"GraphiQL"**. * `batch`: Set the GraphQL view as batch (for using in [Apollo-Client](http://dev.apollodata.com/core/network.html#query-batching) or [ReactRelayNetworkLayer](https://github.com/nodkz/react-relay-network-layer)) * `middleware`: A list of graphql [middlewares](http://docs.graphene-python.org/en/latest/execution/middleware/). + * `validation_rules`: A list of graphql validation rules. * `encode`: the encoder to use for responses (sensibly defaults to `graphql_server.json_encode`). * `format_error`: the error formatter to use for responses (sensibly defaults to `graphql_server.default_format_error`. * `subscriptions`: The GraphiQL socket endpoint for using subscriptions in graphql-ws. diff --git a/docs/sanic.md b/docs/sanic.md index 0b5ec35..e922598 100644 --- a/docs/sanic.md +++ b/docs/sanic.md @@ -51,6 +51,7 @@ This will add `/graphql` endpoint to your app and enable the GraphiQL IDE. `Template.render_async` instead of `Template.render`. If environment is not set, fallbacks to simple regex-based renderer. * `batch`: Set the GraphQL view as batch (for using in [Apollo-Client](http://dev.apollodata.com/core/network.html#query-batching) or [ReactRelayNetworkLayer](https://github.com/nodkz/react-relay-network-layer)) * `middleware`: A list of graphql [middlewares](http://docs.graphene-python.org/en/latest/execution/middleware/). + * `validation_rules`: A list of graphql validation rules. * `max_age`: Sets the response header Access-Control-Max-Age for preflight requests. * `encode`: the encoder to use for responses (sensibly defaults to `graphql_server.json_encode`). * `format_error`: the error formatter to use for responses (sensibly defaults to `graphql_server.default_format_error`. diff --git a/docs/webob.md b/docs/webob.md index 5203c2c..41c0ad1 100644 --- a/docs/webob.md +++ b/docs/webob.md @@ -48,6 +48,7 @@ This will add `/graphql` endpoint to your app and enable the GraphiQL IDE. * `graphiql_html_title`: The graphiql title to display. Defaults to **"GraphiQL"**. * `batch`: Set the GraphQL view as batch (for using in [Apollo-Client](http://dev.apollodata.com/core/network.html#query-batching) or [ReactRelayNetworkLayer](https://github.com/nodkz/react-relay-network-layer)) * `middleware`: A list of graphql [middlewares](http://docs.graphene-python.org/en/latest/execution/middleware/). + * `validation_rules`: A list of graphql validation rules. * `encode`: the encoder to use for responses (sensibly defaults to `graphql_server.json_encode`). * `format_error`: the error formatter to use for responses (sensibly defaults to `graphql_server.default_format_error`. * `enable_async`: whether `async` mode will be enabled. diff --git a/graphql_server/aiohttp/graphqlview.py b/graphql_server/aiohttp/graphqlview.py index a3db1d6..0081174 100644 --- a/graphql_server/aiohttp/graphqlview.py +++ b/graphql_server/aiohttp/graphqlview.py @@ -4,7 +4,7 @@ from typing import List from aiohttp import web -from graphql import ExecutionResult, GraphQLError +from graphql import ExecutionResult, GraphQLError, specified_rules from graphql.type.schema import GraphQLSchema from graphql_server import ( @@ -34,6 +34,7 @@ class GraphQLView: graphiql_template = None graphiql_html_title = None middleware = None + validation_rules = None batch = False jinja_env = None max_age = 86400 @@ -75,6 +76,11 @@ def get_context(self, request): def get_middleware(self): return self.middleware + def get_validation_rules(self): + if self.validation_rules is None: + return specified_rules + return self.validation_rules + @staticmethod async def parse_body(request): content_type = request.content_type @@ -149,6 +155,7 @@ async def __call__(self, request): root_value=self.get_root_value(), context_value=self.get_context(request), middleware=self.get_middleware(), + validation_rules=self.get_validation_rules(), ) exec_res = ( diff --git a/graphql_server/flask/graphqlview.py b/graphql_server/flask/graphqlview.py index a417406..59097d9 100644 --- a/graphql_server/flask/graphqlview.py +++ b/graphql_server/flask/graphqlview.py @@ -7,6 +7,7 @@ from flask.views import View from graphql.error import GraphQLError from graphql.type.schema import GraphQLSchema +from graphql import specified_rules from graphql_server import ( GraphQLParams, @@ -35,6 +36,7 @@ class GraphQLView(View): graphiql_template = None graphiql_html_title = None middleware = None + validation_rules = None batch = False subscriptions = None headers = None @@ -73,6 +75,11 @@ def get_context(self): def get_middleware(self): return self.middleware + def get_validation_rules(self): + if self.validation_rules is None: + return specified_rules + return self.validation_rules + def dispatch_request(self): try: request_method = request.method.lower() @@ -95,6 +102,7 @@ def dispatch_request(self): root_value=self.get_root_value(), context_value=self.get_context(), middleware=self.get_middleware(), + validation_rules=self.get_validation_rules(), ) result, status_code = encode_execution_results( execution_results, diff --git a/graphql_server/quart/graphqlview.py b/graphql_server/quart/graphqlview.py index 9993998..3f01edc 100644 --- a/graphql_server/quart/graphqlview.py +++ b/graphql_server/quart/graphqlview.py @@ -4,7 +4,7 @@ from functools import partial from typing import List -from graphql import ExecutionResult +from graphql import ExecutionResult, specified_rules from graphql.error import GraphQLError from graphql.type.schema import GraphQLSchema from quart import Response, render_template_string, request @@ -37,6 +37,7 @@ class GraphQLView(View): graphiql_template = None graphiql_html_title = None middleware = None + validation_rules = None batch = False enable_async = False subscriptions = None @@ -76,6 +77,11 @@ def get_context(self): def get_middleware(self): return self.middleware + def get_validation_rules(self): + if self.validation_rules is None: + return specified_rules + return self.validation_rules + async def dispatch_request(self): try: request_method = request.method.lower() @@ -98,6 +104,7 @@ async def dispatch_request(self): root_value=self.get_root_value(), context_value=self.get_context(), middleware=self.get_middleware(), + validation_rules=self.get_validation_rules(), ) exec_res = ( [ diff --git a/graphql_server/sanic/graphqlview.py b/graphql_server/sanic/graphqlview.py index 29548e9..e184143 100644 --- a/graphql_server/sanic/graphqlview.py +++ b/graphql_server/sanic/graphqlview.py @@ -4,7 +4,7 @@ from functools import partial from typing import List -from graphql import ExecutionResult, GraphQLError +from graphql import ExecutionResult, GraphQLError, specified_rules from graphql.type.schema import GraphQLSchema from sanic.response import HTTPResponse, html from sanic.views import HTTPMethodView @@ -36,6 +36,7 @@ class GraphQLView(HTTPMethodView): graphiql_template = None graphiql_html_title = None middleware = None + validation_rules = None batch = False jinja_env = None max_age = 86400 @@ -77,6 +78,11 @@ def get_context(self, request): def get_middleware(self): return self.middleware + def get_validation_rules(self): + if self.validation_rules is None: + return specified_rules + return self.validation_rules + async def dispatch_request(self, request, *args, **kwargs): try: request_method = request.method.lower() @@ -103,6 +109,7 @@ async def dispatch_request(self, request, *args, **kwargs): root_value=self.get_root_value(), context_value=self.get_context(request), middleware=self.get_middleware(), + validation_rules=self.get_validation_rules(), ) exec_res = ( [ diff --git a/graphql_server/webob/graphqlview.py b/graphql_server/webob/graphqlview.py index 4eff242..ba54599 100644 --- a/graphql_server/webob/graphqlview.py +++ b/graphql_server/webob/graphqlview.py @@ -5,6 +5,7 @@ from graphql.error import GraphQLError from graphql.type.schema import GraphQLSchema +from graphql import specified_rules from webob import Response from graphql_server import ( @@ -35,6 +36,7 @@ class GraphQLView: graphiql_template = None graphiql_html_title = None middleware = None + validation_rules = None batch = False enable_async = False subscriptions = None @@ -73,6 +75,11 @@ def get_context(self, request): def get_middleware(self): return self.middleware + def get_validation_rules(self): + if self.validation_rules is None: + return specified_rules + return self.validation_rules + def dispatch_request(self, request): try: request_method = request.method.lower() @@ -98,6 +105,7 @@ def dispatch_request(self, request): root_value=self.get_root_value(), context_value=self.get_context(request), middleware=self.get_middleware(), + validation_rules=self.get_validation_rules(), ) result, status_code = encode_execution_results( execution_results,