Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d728f80

Browse filesBrowse files
committed
Improved catch and removed base context from the GraphQLView
1 parent 4a09ea2 commit d728f80
Copy full SHA for d728f80

File tree

Expand file treeCollapse file tree

3 files changed

+10
-12
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+10
-12
lines changed

‎flask_graphql/graphqlview.py

Copy file name to clipboardExpand all lines: flask_graphql/graphqlview.py
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class GraphQLView(View):
1515
schema = None
1616
executor = None
1717
root_value = None
18-
context = None
1918
pretty = False
2019
graphiql = False
2120
graphiql_version = None
@@ -38,8 +37,6 @@ def get_root_value(self):
3837
return self.root_value
3938

4039
def get_context(self):
41-
if self.context is not None:
42-
return self.context
4340
return request
4441

4542
def get_middleware(self):
@@ -65,7 +62,7 @@ def dispatch_request(self):
6562
data = self.parse_body()
6663

6764
show_graphiql = request_method == 'get' and self.should_display_graphiql()
68-
catch = HttpQueryError if show_graphiql else None
65+
catch = show_graphiql
6966

7067
pretty = self.pretty or show_graphiql or request.args.get('pretty')
7168

@@ -97,8 +94,8 @@ def dispatch_request(self):
9794
)
9895

9996
return Response(
97+
result,
10098
status=status_code,
101-
response=result,
10299
content_type='application/json'
103100
)
104101

‎graphql_server/__init__.py

Copy file name to clipboardExpand all lines: graphql_server/__init__.py
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from collections import namedtuple
2+
from collections import namedtuple, MutableMapping
33

44
import six
55
from promise import Promise
@@ -28,7 +28,7 @@ def default_format_error(error):
2828
return {'message': six.text_type(error)}
2929

3030

31-
def run_http_query(schema, request_method, data, query_data=None, batch_enabled=False, catch=None, **execute_options):
31+
def run_http_query(schema, request_method, data, query_data=None, batch_enabled=False, catch=False, **execute_options):
3232
if request_method not in ('get', 'post'):
3333
raise HttpQueryError(
3434
405,
@@ -37,14 +37,17 @@ def run_http_query(schema, request_method, data, query_data=None, batch_enabled=
3737
'Allow': 'GET, POST'
3838
}
3939
)
40-
40+
if catch:
41+
catch = HttpQueryError
42+
else:
43+
catch = SkipException
4144
is_batch = isinstance(data, list)
4245

4346
is_get_request = request_method == 'get'
4447
allow_only_query = is_get_request
4548

4649
if not is_batch:
47-
if not isinstance(data, dict):
50+
if not isinstance(data, (dict, MutableMapping)):
4851
raise HttpQueryError(
4952
400,
5053
'GraphQL params should be a dict. Received {}.'.format(data)
@@ -124,8 +127,6 @@ def get_graphql_params(data, query_data):
124127

125128

126129
def get_response(schema, params, catch=None, allow_only_query=False, **kwargs):
127-
if catch is None:
128-
catch = SkipException
129130
try:
130131
execution_result = execute_graphql_request(
131132
schema,

‎tests/test_graphqlview.py

Copy file name to clipboardExpand all lines: tests/test_graphqlview.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def test_passes_request_into_request_context(client):
438438
}
439439

440440

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.