Skip to content

Commit

Permalink
Fix GraphQL Client Exception handling and logging (#195)
Browse files Browse the repository at this point in the history
remove print statements
  • Loading branch information
somethingmorerelevant authored Jan 27, 2025
1 parent 6e47895 commit 73dec1e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Changelog

## 2.0.1
* Fixed error handling for GraphQL client [#195](https://github.com/singer-io/tap-shopify/pull/195)

## 2.0.0
* Deprecated REST Admin API for products
* GraphQL Support added for deprecated streams
* New Stream `Product Variants` added
* More Details here: [#193](https://github.com/singer-io/tap-shopify/pull/193)
* GraphQL support added for deprecated streams
* New stream `Product Variants` added
* More details here: [#193](https://github.com/singer-io/tap-shopify/pull/193)

## 1.10.0
* Updates the Shopify SDK to 12.3.0
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

setup(
name="tap-shopify",
version="2.0.0",
version="2.0.1",
description="Singer.io tap for extracting Shopify data",
author="Stitch",
url="http://github.com/singer-io/tap-shopify",
classifiers=["Programming Language :: Python :: 3 :: Only"],
python_requires='>=3.5.2',
py_modules=["tap_shopify"],
install_requires=[
# Important: review the monkey-patched method in the GraphQL client when upgrading this dependency.
"ShopifyAPI==12.6.0",
"singer-python==6.0.0",
],
Expand Down
22 changes: 22 additions & 0 deletions tap_shopify/streams/graphql/gql_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import timedelta
import json
import urllib
import shopify

from singer import(
Expand All @@ -20,6 +21,27 @@
class ShopifyGraphQLError(Exception):
"""Custom exception for GraphQL errors"""


def execute_gql(self, query, variables=None, operation_name=None):
"""
This overrides the `execute` method from ShopifyAPI(v12.6.0) to remove the print statement.
Ensure to check the original impl before making any changes or upgrading the SDK version,
as this modification may affect future updates
"""
default_headers = {"Accept": "application/json", "Content-Type": "application/json"}
headers = self.merge_headers(default_headers, self.headers)
data = {"query": query, "variables": variables, "operationName": operation_name}

req = urllib.request.Request(self.endpoint, json.dumps(data).encode("utf-8"), headers)

try:
with urllib.request.urlopen(req) as response:
return response.read().decode("utf-8")
except urllib.error.HTTPError as e:
raise e

shopify.GraphQL.execute = execute_gql

class ShopifyGqlStream(Stream):

data_key = None
Expand Down
3 changes: 0 additions & 3 deletions tap_shopify/streams/metafields.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def get_resource_type_query(self, resource):

@shopify_error_handling
def call_api(self, query_params, query, data_key):
LOGGER.info("Fetching %s %s", self.name, query_params)
response = shopify.GraphQL().execute(query=query, variables=query_params)
response = json.loads(response)
if "errors" in response.keys():
Expand Down Expand Up @@ -106,8 +105,6 @@ def get_parents(self):
query_params = self.get_query_params(last_updated_at, query_end, cursor)
query = get_parent_ids_query(parent)
data = self.call_api(query_params, query, parent)
LOGGER.info("%s : %s", parent, len(data.get("edges")))

for edge in data.get("edges"):
yield (edge.get("node"), resource_alias)

Expand Down

0 comments on commit 73dec1e

Please sign in to comment.