@@ -24,24 +24,33 @@ def setUpClass(cls):
2424
2525 cls ._client = Client ()
2626
27- def query (self , query , op_name = None , input_data = None ):
27+ def query (self , query , op_name = None , input_data = None , variables = None ):
2828 """
2929 Args:
3030 query (string) - GraphQL query to run
3131 op_name (string) - If the query is a mutation or named query, you must
3232 supply the op_name. For annon queries ("{ ... }"),
3333 should be None (default).
3434 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.
3640
3741 Returns:
3842 Response object from client
3943 """
4044 body = {"query" : query }
4145 if op_name :
4246 body ["operation_name" ] = op_name
47+ if variables :
48+ body ["variables" ] = variables
4349 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 }
4554
4655 resp = self ._client .post (
4756 self .GRAPHQL_URL , json .dumps (body ), content_type = "application/json"
0 commit comments