Currently working on the product api graphql migration. I am wondering how should I know when a variant has been deleted?
In the past, I could simple look at the variants in a product, compare it to the variants we have in our app, and if some variants are not there anymore in the Shopify version of the product, we can also delete the variant in our app.
Now that we can have 2000 variants, we never have the 2000 variants in the same query, so I cannot simply compare.
I looked at the webhook but the variant_gids only returns non-deleted variant.
you can try to subscribe to ‘products/update’ webhook (Webhook - REST). According to its definition, it ‘Occurs whenever a product is updated, ordered, or variants are added, removed or updated’, so it may fit for your requirements.
In the webhook payload, you will find all the current variants in the ‘variants’ field.
Anyway, this leads me to the next question to Shopify. Currently, webhook payloads follow REST API data model. Shopify has announced that the REST API is deprecated, but they haven’t said anything about webhooks following REST API data model… It would be great if they could clarify something about this
From what I understood in another thread, the variants field will be deprecated (absolutely not sure about this) in favor of the variant_gids. I think the variants field is too heavy to manage 2000 variants.
But you are right, I should be able to use the variant_gids as it seems to return all the variants (I first thought it was only returning the updated variants).
For your second question, you are absolutely right, it is not clear at all. On my side, I query the product using a GraphQL request every time the webhook is executed. That allows me to keep only 1 format of the product/variant in my code, and not have to deal with two …