productVariants GraphQL endpoint incorrect results

I have another productVariants graphQL bug to report.

Basically, the API will often return incorrect results. This can be for a variety of reasons, but the example I will share here is for an automated collections that make extensive use of title contains or title not contains logic. This isn’t rare though, a lot of Shopify merchants like to do that.

Store ID: 28295626845
Collection ID: 306706251925
Request ID: 5e97dc9c-0c29-4dc9-a6a8-806de1f50a80-1745463602

First, try the REST API to check the product count on the collection:

/admin/collections/306706251925.json

The products_count key returns 127, which I believe is correct.

Next, try to fetch the variants with the productVariants graphQL query:

{
    productVariants(first: 250, query: "collection:306706251925") {
        edges {
            cursor
            node {
                id
            }
        }
    }
}

This returns 59 edges. Every product in Shopify must have at least one variant, so this cannot be correct.

Other observations

  • the Shopify web server takes a pretty long time to respond.
  • Even trying the same query a minute later, now I get 64 edges instead of 59

Among other issues with the productVariants API, this bug has been around for a long time.

I just had a merchant leave a 1 star review for my app because the endpoint did not include product variants that it should have. That one hurt :pensive_face:

2 Likes

Hey again @Chris_Geelhoed :waving_hand: - thanks for reporting this here. I think I was able to replicate this internally on my end here. If I run something like this though, it does look like I retrieve a lot more variants (I think it should be over 300+):

{
  products(first: 250, query:"collection_id:306706251925") {
    nodes {
      id
      inCollection (id:"gid://shopify/Collection/306706251925")
      variants (first:100) {
        nodes {
          id
          title
        }
      }
    }
  }
}

I’ll do some more digging into this on my end here and loop back when I have next steps/more info to share - thanks for flagging this!

Thank you very much Alan :folded_hands:

Hi @Alan_G , just following up on this issue to see if anyone has looked into it yet

Hi Chris,

Our team has identified this is an issue on our side - however I don’t have an ETA on resolving this currently.

Thanks for getting back to me @Liam-Shopify If there is any question about the priority of this bug, I would advocate for high priority as this bug can have a very negative impact on merchants, to the point where they are so upset that they not only uninstall apps but may leave 1 star reviews

@Alan_G I appreciate the idea but that does not work because the query now has nested edges which results in an extremely high query cost. On top of that we should not assume that a product can only have 100 variants, soon that will not be true.

Also, that query does not give the same results in many cases and using it will lead to other bugs. Here is a concrete example:

  1. Merchant has products that have multiple variants. Let’s say a product has 3 variants priced at $5, $12, and $20 for different sizes.
  2. Merchant creates an automated collection which includes all product variants under $10
  3. Merchant uses an app to perform some action on all items in that collection
  4. Using the suggested queries all 3 variants are included in the results, which is certainly not correct

I appreciate the help on this, but want to make it clear that there is no workaround here for app developers.

Hey @Chris_Geelhoed :waving_hand: - thanks for the followups here, really appreciated. Like Liam mentioned, we still can’t guarantee a turnaround time on a resolution, but I’m going to pass along your feedback on the impact you’re seeing internally since I do realize that it’s having a negative merchant impact.

Would you have an app ID handy for your app so that I can take a look on my end here and pass along the specifics to the team as well? Just want to make sure we’re tracking the issue as best we can for you here. Hope to hear from you soon and thanks again for flagging this.

Thanks @Alan_G, My app ID is 4202125 :folded_hands:

1 Like