Skip to content

Commit

Permalink
Allow call on graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-Shutik committed Oct 30, 2024
1 parent 54cfda0 commit b64c970
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions shopify_client/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_grapgql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b64c970

Please sign in to comment.