1010from graphql .type .schema import GraphQLSchema
1111from graphql .utils .get_operation_ast import get_operation_ast
1212
13-
1413from .error import HttpQueryError
1514
1615
@@ -29,57 +28,56 @@ def default_format_error(error):
2928 return {'message' : six .text_type (error )}
3029
3130
32-
3331def run_http_query (schema , request_method , data , query_data = None , batch_enabled = False , catch = None , ** execute_options ):
34- if request_method not in ('get' , 'post' ):
35- raise HttpQueryError (
36- 405 ,
37- 'GraphQL only supports GET and POST requests.' ,
38- headers = {
39- 'Allow' : 'GET, POST'
40- }
41- )
32+ if request_method not in ('get' , 'post' ):
33+ raise HttpQueryError (
34+ 405 ,
35+ 'GraphQL only supports GET and POST requests.' ,
36+ headers = {
37+ 'Allow' : 'GET, POST'
38+ }
39+ )
4240
43- is_batch = isinstance (data , list )
41+ is_batch = isinstance (data , list )
4442
45- is_get_request = request_method == 'get'
46- allow_only_query = is_get_request
43+ is_get_request = request_method == 'get'
44+ allow_only_query = is_get_request
4745
48- if not is_batch :
49- if not isinstance (data , dict ):
50- raise HttpQueryError (
51- 400 ,
52- 'GraphQL params should be a dict. Received {}.' .format (data )
53- )
54- data = [data ]
55- elif not batch_enabled :
46+ if not is_batch :
47+ if not isinstance (data , dict ):
5648 raise HttpQueryError (
5749 400 ,
58- 'Batch GraphQL requests are not enabled.'
50+ 'GraphQL params should be a dict. Received {}.' . format ( data )
5951 )
52+ data = [data ]
53+ elif not batch_enabled :
54+ raise HttpQueryError (
55+ 400 ,
56+ 'Batch GraphQL requests are not enabled.'
57+ )
6058
61- if not data :
62- raise HttpQueryError (
63- 400 ,
64- 'Received an empty list in the batch request.'
65- )
59+ if not data :
60+ raise HttpQueryError (
61+ 400 ,
62+ 'Received an empty list in the batch request.'
63+ )
6664
67- extra_data = {}
68- # If is a batch request, we don't consume the data from the query
69- if not is_batch :
70- extra_data = query_data or {}
65+ extra_data = {}
66+ # If is a batch request, we don't consume the data from the query
67+ if not is_batch :
68+ extra_data = query_data or {}
7169
72- all_params = [get_graphql_params (entry , extra_data ) for entry in data ]
70+ all_params = [get_graphql_params (entry , extra_data ) for entry in data ]
7371
74- responses = [get_response (
75- schema ,
76- params ,
77- catch ,
78- allow_only_query ,
79- ** execute_options
80- ) for params in all_params ]
72+ responses = [get_response (
73+ schema ,
74+ params ,
75+ catch ,
76+ allow_only_query ,
77+ ** execute_options
78+ ) for params in all_params ]
8179
82- return responses , all_params
80+ return responses , all_params
8381
8482
8583def encode_execution_results (execution_results , format_error , is_batch , encode ):
0 commit comments