So i have a problem.... hopefully some of you can assist.
I need to create a product on a store, and I was doing this using the productCreate mutation. I would need to create a single product, with as many as 75 variants. I would also be creating metafields for the variants and hence returning this data too per variant. We ran into issues where we had timeouts from Shopify. Further investigation shows that their stored procs can take too long for a lot of information and therefore would time out. Adding retry logic did help somewhat due to the caching on their side.
However, we still had timeout issues. This is quite problematic for the application we are building.
I therefore adopted a new approach to first create the product, then use the productUpdate mutation to update its variants (and images) in batches of 10 (for example). This worked...only to realise that the productUpdate mutation does not append current data, but rewrites the product data.
The last resort I can think of is to create the product with all its images, latch onto the image Ids and src fields. Then create the variants one by one with productVariantCreate (by using imageId from productCreate). This can work but we are now doing a single variant at a time.... All this to avoid timeouts.
Can anybody please advise on if they have encountered this? And if they have solutions to bulk variant creation on an existing product?
What I ended up needing to do was create the product and variants without images, then upload the images in chunks using productAppendImages mutation. I believe more than 35 images at a time would cause a timeout, might depend on the size of the image though. The ids and other information of the new images can be returned on the previous mutation, which is useful for the next step. You can then use the productVariantUpdate mutation to updated the imageId of the variant image, I used the variant name as the altText for the images I uploaded so I can save the relation. There are probably other ways of doing this but this was one way I solved it.
Thank you, your workaround is great. It's worked for me.
I just want to add some improvements on it.
Firstly, instead of calling productVariantUpdate multiple times to update imageId for each variant, just call productUpdate mutation once to update all variants of the product => you'll reduce the time connecting to the GraphQL server.
Secondly, because we will call productUpdate mutation to update ALL variants later, when we create product with productCreate mutation, just pass a dummy variants array with ONE variant to the query to reduce the operation time. In my experience, creating 1 product with 80 variants cost 10 seconds and creating 1 product with 1 variant cost only 1 second.
Lastly, if you don't have too many product images, just pass the images to productCreate mutation to ignore productAppendImages step.
Overall, I believe the solution for this issue is: productCreate mutation (with only one variant) => productAppendImages mutation (optional) => productUpdate mutation (all variants including imageIds)