How to fetch product media gallery images URL using GraphQl Magento 2?

You can fetch the product media gallery images as well as the main Image, Thumbnail, Swatch Image, and Small Image URL by GraphQl.

You have to pass SKU in the product search query to get the product image URL.

GraphQl Query Request Body:

query {
  products(filter: { sku: { eq: "<PRODUCT_SKU>" } }) {
    items {
      swatch_image
      small_image {
        url
        label
        position
        disabled
      }
      thumbnail {
        url
        label
        position
        disabled
      }
      image {
        url
        label
        position
        disabled
      }
      media_gallery {
       url
        label
        position
        disabled
      }
    }
  }
}

 

Replace <PRODUCT_SKU> with your original SKU in the query request body.

Once you run the query, you will get the result as the URL of the product. If the specific image type is not found return it as null otherwise result will be a full product image URL.

The media gallery returns the list of all the images of the product as an array.