Get image.id or media.id using Graphql API

Shopify Expert
4 0 1

I am working on an app where a user can assign multiple media items to a variant. This is working good using rest admin api because I was able to fetch the image-id using Rest admin API and saved it in my database as variant-id, image-id pairs. On the storefront side, I added a custom attribute in liquid coding of the theme like this: 
data-image-id="{{ image.id }}" to identify and compare the images with image-ids saved in my database.

Now I want to make use of the new media object that shopify has introduced. I am using graphQl API to fetch the product images. The Graphql API is returning an image id in a URL like format: "gid://shopify/images/10079785100". The problem is, I am unable to compare and somehow link this id to the image-id or media-id on the storefront. 

So my question is:
1. How can I fetch the actual image.id or media-id for a media item using graphQL API?
2. If that is not possible, then how can I add this gid as a custom attribute for image tag in product page image gallery within the theme code? 

Thanks for any help in advance!

Cheers!

0 Likes