Skip to content

Update context and root executor options #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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