Skip to content
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

Fixed the context option #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion flask_graphql/graphqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class GraphQLView(View):
graphiql_template = None
graphiql_html_title = None
middleware = None
context = None
batch = False

methods = ['GET', 'POST', 'PUT', 'DELETE']
Expand All @@ -39,7 +40,7 @@ def get_root_value(self):
return self.root_value

def get_context(self):
return request
return self.context or request

def get_middleware(self):
return self.middleware
Expand Down
6 changes: 3 additions & 3 deletions tests/test_graphqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def test_passes_request_into_request_context(client):
}


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

Expand Down Expand Up @@ -514,8 +514,8 @@ 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):
response = client.post(
Expand Down