How to Get Related Products Using GraphQL in Magento 2

Do you want to get related products using GraphQL Query in Magento 2?

If you want to get all the related products of the specific product using GraphQL, You will need to use the related product GraphQL Query to retrieve all those products.

In this tutorial we are going to show you how to get related products using GraphQL in Magento 2.

Let’s start!

You need to use below GraphQL query to get related products.

{
  products(filter: { sku: { eq: "MT07" } }) {
    items {
      id
      name
      sku
      related_products {
        id
        sku
        stock_status
        short_description {
          html
        }
        url_key
        name
        special_price
        price_range {
          minimum_price {
            final_price {
              value
              currency
            }
          }
          maximum_price {
            final_price {
              value
              currency
            }
          }
        }
      }
    }
  }
}

In the above GraphQL query, you can see related_products{} field which helps to get all the related products.

As per above given query, If the product with sku as “MT07” contains related products assigned, the output will have all the assigned products array with related_products key otherwise it will display an empty array.

See below results.

Get Related Products Using GraphQL in Magento 2

You can use ChromeiQL tool to test and run GraphQL Query in Magento 2.

How to Get Related Products Using GraphQL in Magento 2 Click To Tweet

If you liked this tutorial, then please subscribe to our Newsletter for Magento tutorials. You can also find us on Twitter and Facebook. If you have any problem or would like to add to the discussion, leave a comment below!

You May Also Like

Editorial Staff

About the Author: Editorial Staff

Editorial Staff at the MageBeginners is a team of Magento experts writing about Magento Tutorials, Themes, Extensions, Guides, Tricks and much more...

Leave a Reply

Your email address will not be published. Required fields are marked *