Beware GraphQL Mutation createCollection

Shopify Expert
4355 36 462

If you use this mutation to create a Collection, and you set up some rules, and the collection indeed gets created, there is a huge gotcha waiting for you.


There is no signal that Shopify has actually built the collection. There is no signal to know that all the products in the shop that match the rules are in the collection. As a consequence, your coding is suspect.


- there is no way to know how many products should/could be in the collection, except to use the Admin to create a dupe of this collection in terms of rules, and see what that count is.

- graphQL returns an ID for the collection with the rules, and initially anyway,  0 products. The collection has not been built yet (read: populated with products)


So how does one deal with this? You can sit around and twiddle your thumbs, and wait a few minutes, and then ask how many products are in the collection. But will you know that that is the true number? How would you know?


This is where asynchronous communications with an API tend to break down. At least with bulk operations you can, ahem, poll... but with this mutation, you don't get that signal to poll on.




Custom Shopify Apps built just for you!
16 0 4

Is this still true?