10
10
from graphql .type .schema import GraphQLSchema
11
11
from graphql .utils .get_operation_ast import get_operation_ast
12
12
13
-
14
13
from .error import HttpQueryError
15
14
16
15
@@ -29,57 +28,56 @@ def default_format_error(error):
29
28
return {'message' : six .text_type (error )}
30
29
31
30
32
-
33
31
def 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
+ )
42
40
43
- is_batch = isinstance (data , list )
41
+ is_batch = isinstance (data , list )
44
42
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
47
45
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 ):
56
48
raise HttpQueryError (
57
49
400 ,
58
- 'Batch GraphQL requests are not enabled.'
50
+ 'GraphQL params should be a dict. Received {}.' . format ( data )
59
51
)
52
+ data = [data ]
53
+ elif not batch_enabled :
54
+ raise HttpQueryError (
55
+ 400 ,
56
+ 'Batch GraphQL requests are not enabled.'
57
+ )
60
58
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
+ )
66
64
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 {}
71
69
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 ]
73
71
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 ]
81
79
82
- return responses , all_params
80
+ return responses , all_params
83
81
84
82
85
83
def encode_execution_results (execution_results , format_error , is_batch , encode ):
0 commit comments