Shopify API matches product and product variants in an inconsistent way

The Graph QL API has a bug right now that is causing confusion for Shopify developers and Shopify merchants. It can be easily reproduced on any store in about 5 minutes.

Steps to reproduce:

Create an automated collection that includes all items that have a tag of “Snow-Devil”

Next, add the tag “snow devil” to one product in the store:

If you check the collection, you will see that the product is now matched in the collection

Next, run this graph QL query:

query {
  productVariants(
    first: 250
    query: "collection:12345"
  ) {
    edges {
      node {
        id
        sku
        title
      }
    }
  }
}

The API will return an empty array of edges, which contradicts the information shown in the Shopify admin dashboard.

If you now change the tag on the product to be an exact match (“Snow-Devil” instead of “snow devil”) the API will work as expected and include the product.

If Shopify wants to normalize the text in a tag that is fine, but please be consistent in that approach instead of doing it in some places and not in other places.

Hi @Chris_Geelhoed :waving_hand: thanks for the flag.

I see what you mean here. You’re spot on with your comment about consistency as well.

As a workaround for the time being, you can use a query like this if it works for you which is returning the expected results regardless of how the product tags are formatted:

  collection(id: "gid://shopify/Collection/12345") {
    title
    products(first: 250) {
      edges {
        node {
          id
          title
          variants(first: 100) {
            edges {
              node {
                id
                sku
                title
              }
            }
          }
        }
      }
    }
  }
}

I’ll dig into this further and follow up with you here as soon as I have more to share.

Hi @Wes-Dev-Shopify

Thanks for the reply.

Unfortunately, that work around is not good.

Nesting edges in the graph QL query (collection => products => variants) is not efficient from a usage limit standpoint, which makes it impractical for real world usage.

More importantly, it is simply wrong sometimes. Here is a concrete example that is also easy to reproduce, which proves the workaround suggested is wrong.

First, have a product with multiple variants that have different prices.

Next, create an automated collection that includes products below a price, where the price is greater than some variants but less than other variants ($75 in my example)

Next, run the the suggested graphQL query and inspect the results. It will return items that have a price less than $75

So, nesting the query as Collection → products → variants is not a valid way to get the variants within a collection and should not be suggested as a workaround.

Hey @Chris_Geelhoed - thanks for the callout and for the second example. You’re right on both counts. The nested collection > products > variants path isn’t a dependable workaround: it’s heavy on query cost, and as you showed, it returns the wrong variants the moment a collection rule keys off price (or anything else evaluated at the variant level).

I did some digging regarding the smart collection membership behavior and I want to be transparent here: I don’t have a timeline I can share, but the way collection membership is evaluated is being reworked more broadly on our end, and this inconsistency should resolve as part of that work. I’d rather be upfront about that than leave you waiting on a fix that isn’t coming on its own in the short term.

I’ll follow up here if I have anything more concrete to share.

Thank you @Wes-Dev-Shopify future updates (whenever those may be) would be greatly appreciated :folded_hands: