Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

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 15

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
18 1 6

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