@@ -24,24 +24,33 @@ def setUpClass(cls):
24
24
25
25
cls ._client = Client ()
26
26
27
- def query (self , query , op_name = None , input_data = None ):
27
+ def query (self , query , op_name = None , input_data = None , variables = None ):
28
28
"""
29
29
Args:
30
30
query (string) - GraphQL query to run
31
31
op_name (string) - If the query is a mutation or named query, you must
32
32
supply the op_name. For annon queries ("{ ... }"),
33
33
should be None (default).
34
34
input_data (dict) - If provided, the $input variable in GraphQL will be set
35
- to this value
35
+ to this value. If both ``input_data`` and ``variables``,
36
+ are provided, the ``input`` field in the ``variables``
37
+ dict will be overwritten with this value.
38
+ variables (dict) - If provided, the "variables" field in GraphQL will be
39
+ set to this value.
36
40
37
41
Returns:
38
42
Response object from client
39
43
"""
40
44
body = {"query" : query }
41
45
if op_name :
42
46
body ["operation_name" ] = op_name
47
+ if variables :
48
+ body ["variables" ] = variables
43
49
if input_data :
44
- body ["variables" ] = {"input" : input_data }
50
+ if variables in body :
51
+ body ["variables" ]["input" ] = input_data
52
+ else :
53
+ body ["variables" ] = {"input" : input_data }
45
54
46
55
resp = self ._client .post (
47
56
self .GRAPHQL_URL , json .dumps (body ), content_type = "application/json"
0 commit comments