GraphQL API: Timeout issues with productCreate for products with many variants

danielkolb
New Member
2 0 1

Hello,

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?

Thank you!

RyanPadilla
New Member
2 0 1

Chiming in to say I've encountered this issue as well, and on products with variants as low as 46. Were you able to figure out anything further in regards to a solution or workaround? I had considered the single variant upload as well, but wasn't too keen on that at all...

0 Likes
manhnq94
Tourist
10 1 1

I had the same error as well.

My product has 80 variants and it timeout for the productCreate mutation! I don't know how to get the request ID and don't have any workaround too. It's quite a big problem for me.

Hope any member of Shopify dev team take a look at this post.

0 Likes
RyanPadilla
New Member
2 0 1

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.

manhnq94
Tourist
10 1 1

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)