Help deleting images via GraphQl

Hello, 1`st post ever, I’ve been using REST successfully for a couple of years with Shopify. I am attempting to move over to GraphQL but not sure if it’s me or other folks having same issues.

I look in the Documentation and it tells me the function is deprecated, but in the changelog it tells me to use it. totally confused. I’ve been coding since the 80’s and never been more confused

The function is: productDeleteMedia

It will only let me attach 1 image to post since i’m a new user :frowning:

Thanks
Jaime

Hey Jaime,

Welcome to the .dev community :slight_smile: Could you use the fileUpdate mutation instead? It wouldn’t delete the image, but it would remove its association with the product, using the referencesToRemove field. The mutation would look something like this:

mutation UpdateFile {
  fileUpdate(files: {
    id: "gid://shopify/GenericFile/1072273203",
    referencesToRemove: ["gid://shopify/Product/108828309"]
  }) {
    files {
      id
      alt
    }
    userErrors {
      field
      message
    }
  }
}
1 Like

Thanks, I’ll give it a try.
But the docs need to tell us what to use, i waisted a lot of time trying to figure out what to use and not use :frowning:

Totally get that this was confusing. Which changelog update did you read? It’s possible it was outdated - I’d recommend always going by the actual reference docs instead of changelog updates (which are for news).

It was right on top, can you send me a link for best way to look?
Still have a lot to complete

Thanks,
Jaime

(attachments)