diff --git a/shopify_client/graphql.py b/shopify_client/graphql.py index f85caca..7c36076 100644 --- a/shopify_client/graphql.py +++ b/shopify_client/graphql.py @@ -14,6 +14,9 @@ def __init__(self, client): def __build_url(self, **params): return self.endpoint + + def __call__(self, *args, **kwargs): + return self.query(*args, **kwargs) def query(self, query, variables=None, operation_name=None): try: diff --git a/tests/test_grapgql.py b/tests/test_grapgql.py index 97f84be..b838a1e 100644 --- a/tests/test_grapgql.py +++ b/tests/test_grapgql.py @@ -39,3 +39,16 @@ def test_query_handles_json_error(graphql, mock_client): mock_client.post.side_effect = json.JSONDecodeError("JSON Decode Error", "", 0) response = graphql.query(query="query { key }") assert response == {} + +def test_graphql_call(graphql, mock_client): + mock_query_response = {"data": {"exampleField": "exampleValue"}} + mock_client.post.return_value = mock_query_response + + # Call the GraphQL client like a function + response = graphql("query { exampleField }") + + # Verify that the query method was called correctly + mock_client.post.assert_called_once_with("graphql.json", json={'query': 'query { exampleField }', 'variables': None, 'operationName': None}) + + # Assert the response is as expected + assert response == mock_query_response