Skip to content

Commit

Permalink
Added support for dynamic backends. Update version to 2.0rc0
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Jun 5, 2018
1 parent ab5831f commit 068ee71
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ matrix:
env: TOX_ENV=pypy
- python: '2.7'
env: TOX_ENV=py27
- python: '3.3'
env: TOX_ENV=py33
- python: '3.4'
env: TOX_ENV=py34
- python: '3.5'
env: TOX_ENV=py35,import-order,flake8
env: TOX_ENV=py35
- python: '3.6'
env: TOX_ENV=py36,import-order,flake8
cache:
directories:
- $HOME/.cache/pip
Expand Down
18 changes: 15 additions & 3 deletions flask_graphql/graphqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -68,19 +72,27 @@ 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,
data,
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,
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
6 changes: 5 additions & 1 deletion tests/app.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
6 changes: 3 additions & 3 deletions tests/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
)
Expand Down
17 changes: 15 additions & 2 deletions tests/test_graphqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) }',
Expand Down Expand Up @@ -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!'}]
}


Expand All @@ -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'}]
}

Expand Down
10 changes: 5 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ 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
commands =
py{py,27,33,34,35}: py.test tests {posargs}
py{py,27,34,35,36}: py.test tests {posargs}

[testenv:flake8]
basepython=python3.5
basepython=python3.6
deps = flake8
commands =
flake8 flask_graphql

[testenv:import-order]
basepython=python3.5
basepython=python3.6
deps =
isort
graphql-core>=1.0
graphql-core>=2.1rc1
Flask>=0.10.0
commands =
isort --check-only flask_graphql/ -rc

0 comments on commit 068ee71

Please sign in to comment.