Skip to content

Commit d29cc6f

Browse files
authored
Update context and root executor options (#74)
* 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
1 parent 0137ca1 commit d29cc6f

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

flask_graphql/graphqlview.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, **kwargs):
3838
def get_root_value(self):
3939
return self.root_value
4040

41-
def get_context(self):
41+
def get_context_value(self):
4242
return request
4343

4444
def get_middleware(self):
@@ -89,8 +89,8 @@ def dispatch_request(self):
8989
backend=self.get_backend(),
9090

9191
# Execute options
92-
root=self.get_root_value(),
93-
context=self.get_context(),
92+
root_value=self.get_root_value(),
93+
context_value=self.get_context_value(),
9494
middleware=self.get_middleware(),
9595
**extra_options
9696
)

setup.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from setuptools import setup, find_packages
22

3-
required_packages = ["graphql-core>=2.1,<3", "flask>=0.7.0", "graphql-server-core>=1.1,<2"]
3+
required_packages = [
4+
"graphql-core>=2.3,<3",
5+
"flask>=0.7.0",
6+
"graphql-server-core>=1.1,<2",
7+
]
48

59
setup(
610
name="Flask-GraphQL",

tests/test_graphiqlview.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_graphiql_renders_pretty(client):
2323
' "test": "Hello World"\n'
2424
' }\n'
2525
'}'
26-
).replace("\"","\\\"").replace("\n","\\n")
26+
).replace("\"", "\\\"").replace("\n", "\\n")
2727

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

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

3535

3636
@pytest.mark.parametrize('app', [create_app(graphiql=True, graphiql_html_title="Awesome")])
37-
def test_graphiql_custom_title(client):
37+
def test_graphiql_custom_title(app, client):
3838
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
3939
assert '<title>Awesome</title>' in response.data.decode('utf-8')

tests/test_graphqlview.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
def app():
2020
return create_app()
2121

22+
2223
def url_string(**url_params):
2324
string = url_for('graphql')
2425

@@ -328,7 +329,7 @@ def test_allows_post_with_get_operation_name(client):
328329

329330

330331
@pytest.mark.parametrize('app', [create_app(pretty=True)])
331-
def test_supports_pretty_printing(client):
332+
def test_supports_pretty_printing(app, client):
332333
response = client.get(url_string(query='{test}'))
333334

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

342343

343344
@pytest.mark.parametrize('app', [create_app(pretty=False)])
344-
def test_not_pretty_by_default(client):
345+
def test_not_pretty_by_default(app, client):
345346
response = client.get(url_string(query='{test}'))
346347

347348
assert response.data.decode() == (
@@ -451,11 +452,10 @@ def test_passes_request_into_request_context(client):
451452
}
452453

453454

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

458-
459459
assert response.status_code == 200
460460
assert response_json(response) == {
461461
'data': {
@@ -468,7 +468,7 @@ def test_post_multipart_data(client):
468468
query = 'mutation TestMutation { writeTest { test } }'
469469
response = client.post(
470470
url_string(),
471-
data= {
471+
data={
472472
'query': query,
473473
'file': (StringIO(), 'text1.txt'),
474474
},
@@ -480,7 +480,7 @@ def test_post_multipart_data(client):
480480

481481

482482
@pytest.mark.parametrize('app', [create_app(batch=True)])
483-
def test_batch_allows_post_with_json_encoding(client):
483+
def test_batch_allows_post_with_json_encoding(app, client):
484484
response = client.post(
485485
url_string(),
486486
data=jl(
@@ -498,7 +498,7 @@ def test_batch_allows_post_with_json_encoding(client):
498498

499499

500500
@pytest.mark.parametrize('app', [create_app(batch=True)])
501-
def test_batch_supports_post_json_query_with_json_variables(client):
501+
def test_batch_supports_post_json_query_with_json_variables(app, client):
502502
response = client.post(
503503
url_string(),
504504
data=jl(
@@ -514,10 +514,10 @@ def test_batch_supports_post_json_query_with_json_variables(client):
514514
# 'id': 1,
515515
'data': {'test': "Hello Dolly"}
516516
}]
517-
518-
517+
518+
519519
@pytest.mark.parametrize('app', [create_app(batch=True)])
520-
def test_batch_allows_post_with_operation_name(client):
520+
def test_batch_allows_post_with_operation_name(app, client):
521521
response = client.post(
522522
url_string(),
523523
data=jl(

0 commit comments

Comments
 (0)