Skip to content

Commit

Permalink
Update context and root executor options (#74)
Browse files Browse the repository at this point in the history
* Pass context and root value to executor opts

* Bump graphql-core minimum version to 2.3

* Fix graphqlview custom context test

* Pass app fixture on graphiqlview
  • Loading branch information
KingDarBoja committed Feb 25, 2020
1 parent 0137ca1 commit d29cc6f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
6 changes: 3 additions & 3 deletions flask_graphql/graphqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, **kwargs):
def get_root_value(self):
return self.root_value

def get_context(self):
def get_context_value(self):
return request

def get_middleware(self):
Expand Down Expand Up @@ -89,8 +89,8 @@ def dispatch_request(self):
backend=self.get_backend(),

# Execute options
root=self.get_root_value(),
context=self.get_context(),
root_value=self.get_root_value(),
context_value=self.get_context_value(),
middleware=self.get_middleware(),
**extra_options
)
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from setuptools import setup, find_packages

required_packages = ["graphql-core>=2.1,<3", "flask>=0.7.0", "graphql-server-core>=1.1,<2"]
required_packages = [
"graphql-core>=2.3,<3",
"flask>=0.7.0",
"graphql-server-core>=1.1,<2",
]

setup(
name="Flask-GraphQL",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_graphiqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_graphiql_renders_pretty(client):
' "test": "Hello World"\n'
' }\n'
'}'
).replace("\"","\\\"").replace("\n","\\n")
).replace("\"", "\\\"").replace("\n", "\\n")

assert pretty_response in response.data.decode('utf-8')

Expand All @@ -34,6 +34,6 @@ def test_graphiql_default_title(client):


@pytest.mark.parametrize('app', [create_app(graphiql=True, graphiql_html_title="Awesome")])
def test_graphiql_custom_title(client):
def test_graphiql_custom_title(app, client):
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
assert '<title>Awesome</title>' in response.data.decode('utf-8')
22 changes: 11 additions & 11 deletions tests/test_graphqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
def app():
return create_app()


def url_string(**url_params):
string = url_for('graphql')

Expand Down Expand Up @@ -328,7 +329,7 @@ def test_allows_post_with_get_operation_name(client):


@pytest.mark.parametrize('app', [create_app(pretty=True)])
def test_supports_pretty_printing(client):
def test_supports_pretty_printing(app, client):
response = client.get(url_string(query='{test}'))

assert response.data.decode() == (
Expand All @@ -341,7 +342,7 @@ def test_supports_pretty_printing(client):


@pytest.mark.parametrize('app', [create_app(pretty=False)])
def test_not_pretty_by_default(client):
def test_not_pretty_by_default(app, client):
response = client.get(url_string(query='{test}'))

assert response.data.decode() == (
Expand Down Expand Up @@ -451,11 +452,10 @@ def test_passes_request_into_request_context(client):
}


@pytest.mark.parametrize('app', [create_app(get_context=lambda:"CUSTOM CONTEXT")])
def test_supports_pretty_printing(client):
@pytest.mark.parametrize('app', [create_app(get_context_value=lambda:"CUSTOM CONTEXT")])
def test_supports_pretty_printing_with_custom_context(app, client):
response = client.get(url_string(query='{context}'))


assert response.status_code == 200
assert response_json(response) == {
'data': {
Expand All @@ -468,7 +468,7 @@ def test_post_multipart_data(client):
query = 'mutation TestMutation { writeTest { test } }'
response = client.post(
url_string(),
data= {
data={
'query': query,
'file': (StringIO(), 'text1.txt'),
},
Expand All @@ -480,7 +480,7 @@ def test_post_multipart_data(client):


@pytest.mark.parametrize('app', [create_app(batch=True)])
def test_batch_allows_post_with_json_encoding(client):
def test_batch_allows_post_with_json_encoding(app, client):
response = client.post(
url_string(),
data=jl(
Expand All @@ -498,7 +498,7 @@ def test_batch_allows_post_with_json_encoding(client):


@pytest.mark.parametrize('app', [create_app(batch=True)])
def test_batch_supports_post_json_query_with_json_variables(client):
def test_batch_supports_post_json_query_with_json_variables(app, client):
response = client.post(
url_string(),
data=jl(
Expand All @@ -514,10 +514,10 @@ def test_batch_supports_post_json_query_with_json_variables(client):
# 'id': 1,
'data': {'test': "Hello Dolly"}
}]


@pytest.mark.parametrize('app', [create_app(batch=True)])
def test_batch_allows_post_with_operation_name(client):
def test_batch_allows_post_with_operation_name(app, client):
response = client.post(
url_string(),
data=jl(
Expand Down

0 comments on commit d29cc6f

Please sign in to comment.