Product Variant Append Media Graphql Mutation failure

Hi, I’m re-posting a question that was unanswered on the old forums.

I’m looking to upload and attach Media to variants. The following scenario fails with this user error: “Non-ready media cannot be attached to variants”

  1. Create Product (succeed)
  2. Upload Media (succeed)
  3. Attach Media to Product (succeed)
  4. Attach Product Media to Variant (fails)

Has anyone ever figured out a way to deal with this? If I debug and go through the steps at human speed it works. How is anyone supposed to know when the media is ready without making another API call to check? this is going to take longer than it did the old REST way, which will no longer be an option soon…

Hi Brian,

Just looking to understand this issue a bit more.

If I debug and go through the steps at human speed it works.

Is the issue that the media is not accessible to use as the originalSource input field at the time of doing the productUpdate mutation?

I don’t know what the issue is. I am not using the productUpdate mutation,
I’m using productVariantAppendMedia. This is the call that returns “Non-ready media cannot be attached to variants”

Do you use the productUpdate mutation at all in your flow?

yes, I use it for making any other changes that the mutation supports

Hey Brian,

When you’re uploading/attaching the media to the product, you need to check for the media status Media - GraphQL Admin

Because it could be processing videos etc as well as images, these could take a little time to process. Which is why I think you’ll be seeing it working at human speed.
I would check this status, until its ready.
Simplest way you could just put a small wait in. Or if you wanted a really robust way, you could poll until its ready.

Then you’ll be able to attach to the variant

Yes, I had to resort to doing a check of the status until it’s ready. Unfortunately this extra check will slow down the overall process, compared to using the REST API. It seemed strange to me that you could attach an image to a product without the media being ready, but not associate that image to a particular variant of that product…

The product team did a really good explanation of why its this way in GraphQL and what they are trying to support Product model and components

As to the product/variant difference, I would guess that its because of the changes they’ve made to support 2k variants in future.