diff --git a/flask_graphql/graphqlview.py b/flask_graphql/graphqlview.py index ceca3eb..ff257b3 100644 --- a/flask_graphql/graphqlview.py +++ b/flask_graphql/graphqlview.py @@ -17,6 +17,7 @@ class GraphQLView(View): root_value = None pretty = False graphiql = False + backend = None graphiql_version = None graphiql_template = None graphiql_html_title = None @@ -43,6 +44,9 @@ def get_context(self): def get_middleware(self): return self.middleware + def get_backend(self): + return self.backend + def get_executor(self): return self.executor @@ -68,6 +72,13 @@ def dispatch_request(self): pretty = self.pretty or show_graphiql or request.args.get('pretty') + extra_options = {} + executor = self.get_executor() + if executor: + # We only include it optionally since + # executor is not a valid argument in all backends + extra_options['executor'] = executor + execution_results, all_params = run_http_query( self.schema, request_method, @@ -75,12 +86,13 @@ def dispatch_request(self): query_data=request.args, batch_enabled=self.batch, catch=catch, + backend=self.get_backend(), # Execute options - root_value=self.get_root_value(), - context_value=self.get_context(), + root=self.get_root_value(), + context=self.get_context(), middleware=self.get_middleware(), - executor=self.get_executor(), + **extra_options ) result, status_code = encode_execution_results( execution_results, diff --git a/setup.py b/setup.py index 538317b..f86347f 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,14 @@ from setuptools import setup, find_packages required_packages = [ - 'graphql-core>=1.0', + 'graphql-core>=2.1rc1', 'flask>=0.7.0', - 'graphql-server-core>=1.0.dev' + 'graphql-server-core>=1.1rc0' ] setup( name='Flask-GraphQL', - version='1.4.1', + version='2.0rc0', description='Adds GraphQL support to your Flask application', long_description=open('README.rst').read(), url='https://github.com/graphql-python/flask-graphql', diff --git a/tests/app.py b/tests/app.py index 9f11aee..0d38502 100644 --- a/tests/app.py +++ b/tests/app.py @@ -1,12 +1,16 @@ from flask import Flask from flask_graphql import GraphQLView from .schema import Schema +from graphql import GraphQLCachedBackend +# from quiver.backend import GraphQLQuiverBackend def create_app(path='/graphql', **kwargs): + # backend = GraphQLCachedBackend(GraphQLQuiverBackend({"async_framework": "PROMISE"})) + backend = None app = Flask(__name__) app.debug = True - app.add_url_rule(path, view_func=GraphQLView.as_view('graphql', schema=Schema, **kwargs)) + app.add_url_rule(path, view_func=GraphQLView.as_view('graphql', schema=Schema, backend=backend, **kwargs)) return app diff --git a/tests/schema.py b/tests/schema.py index 742ca09..f841672 100644 --- a/tests/schema.py +++ b/tests/schema.py @@ -12,15 +12,15 @@ def resolve_raises(*_): fields={ 'thrower': GraphQLField(GraphQLNonNull(GraphQLString), resolver=resolve_raises), 'request': GraphQLField(GraphQLNonNull(GraphQLString), - resolver=lambda obj, args, context, info: context.args.get('q')), + resolver=lambda obj, info: info.context.args.get('q')), 'context': GraphQLField(GraphQLNonNull(GraphQLString), - resolver=lambda obj, args, context, info: context), + resolver=lambda obj, info: info.context), 'test': GraphQLField( type=GraphQLString, args={ 'who': GraphQLArgument(GraphQLString) }, - resolver=lambda obj, args, context, info: 'Hello %s' % (args.get('who') or 'World') + resolver=lambda obj, info, who='World': 'Hello %s' % who ) } ) diff --git a/tests/test_graphqlview.py b/tests/test_graphqlview.py index 5f53dfe..77626d4 100644 --- a/tests/test_graphqlview.py +++ b/tests/test_graphqlview.py @@ -194,6 +194,19 @@ def test_allows_post_with_url_encoding(client): } +# def test_benchmark(client, benchmark): +# url = url_string() +# data = urlencode(dict(query='{test}')) +# def fun(): +# return client.post(url_string(), data=data, content_type='application/x-www-form-urlencoded') + +# response = benchmark(fun) +# assert response.status_code == 200 +# assert response_json(response) == { +# 'data': {'test': "Hello World"} +# } + + def test_supports_post_json_query_with_string_variables(client): response = client.post(url_string(), data=j( query='query helloWho($who: String){ test(who: $who) }', @@ -353,7 +366,7 @@ def test_handles_field_errors_caught_by_graphql(client): assert response.status_code == 200 assert response_json(response) == { 'data': None, - 'errors': [{'locations': [{'column': 2, 'line': 1}], 'message': 'Throws!'}] + 'errors': [{'locations': [{'column': 2, 'line': 1}], 'path': ['thrower'], 'message': 'Throws!'}] } @@ -362,7 +375,7 @@ def test_handles_syntax_errors_caught_by_graphql(client): assert response.status_code == 400 assert response_json(response) == { 'errors': [{'locations': [{'column': 1, 'line': 1}], - 'message': 'Syntax Error GraphQL request (1:1) ' + 'message': 'Syntax Error GraphQL (1:1) ' 'Unexpected Name "syntaxerror"\n\n1: syntaxerror\n ^\n'}] } diff --git a/tox.ini b/tox.ini index 407f02c..caf146c 100644 --- a/tox.ini +++ b/tox.ini @@ -8,7 +8,7 @@ setenv = deps = pytest>=2.7.2 pytest-flask>=0.10.0 - graphql-core>=1.0 + graphql-core>=2.1rc1 graphql-server-core>=1.0.dev Flask>=0.10.0 pytest-cov @@ -25,7 +25,7 @@ commands = basepython=python3.5 deps = isort - graphql-core>=1.0 + graphql-core>=2.1rc1 Flask>=0.10.0 commands = isort --check-only flask_graphql/ -rc