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

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

RaviAmbasana
Visitor
1 0 0

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?

Replies 4 (4)

VivekH
Excursionist
12 1 14

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.

Veesy
Shopify Partner
16 0 5

It's only first 15, is there a way to remove the "first" filter ?

DenisSabolotni
Shopify Partner
12 1 20

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

chenpeng
Shopify Partner
1 0 0

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

It can't find it

chenpeng_0-1666253243267.png