GraphQL: How do I get all product variants by product ID for each product?

Hi, I am trying to get product variants for a product using the product ID. I am querying the productVariants and my query looks like this:

{
  productVariants(first:10 ) {
    edges {
      node {
        id
        product {
          id
        }
      }
    }
  }
}

I want to get only the product variants that match a particular product id. How can I do that?

Hey @RaviAmbasana ,

You can query all product variants of a product using this -

{
  product(id: "gid://shopify/Product/1234") {
    variants(first: 15) {
      edges {
        node {
          id
          sku
        }
      }
    }
  }
}

Hope this helps.

It’s only first 15, is there a way to remove the “first” filter ?

Unfortunately not. Shopify did that on purpose to reduce the “cost” of queries.

You could implement “paging”, to get all results through multiple small requests, instead of a big one, that gets everything for you:

https://shopify.dev/api/usage/pagination-graphql

How to query the Product Variants ID of a product on the Shopify Android SDK?

It can’t find it