Conversion: Connections from a resource
Until further notice, Shopify will continue to send product webhook data in a REST-like format. Tasks that only use the fields available in the webhook (e.g. product.title
) may not need to be converted by the deprecation notice date. However, if connections to other resources are made from that product (e.g. product.collections
), then that will require conversion.
This is a simple task to loop through a product's collections, check if the collection contains a certain tag, then log out the collection title.
The GraphQL version of the the task above use a paginated query to get all of the collections a product is a member of. The outer loop upper range (e.g. the 10 in {% for n in (1..10) %}
) is arbitrary, and you may adjust it to the approximate maximum number of collections any given product might have.
The event preview block in this task sample makes this code appear to be overly verbose, however the preview block is often an important step to ensure that Mechanic prompts for the correct scopes for reading and writing Shopify API data.
To assist with generating a paginated query block, you can use the "paginated_query" snippet in the Mechanic code editor, and it will prompt you to choose the object type to paginate over (e.g. products).
Last updated