Prodcut collection count and get all product collections graphql query result is not same

Product collection count received in graphql API response is different from actual getting product collections count. I have no smart collection added in my store.

Hey @Rajanverma ,

This is a classic pagination vs. count discrepancy. The totalCount field is reporting that there are 2 collections in your store, but when you actually fetch the collections themselves, you’re only seeing one (“Home page1”).

Several potential causes for this:

  1. Hidden or unpublished collections: The second collection might exist but is unpublished or hidden from the storefront.
  2. Permission/visibility issues: Depending on your API credentials, some collections might not be visible in the nodes response.
  3. Smart collections vs. custom collections: Shopify distinguishes between these two types, and your query might be retrieving one type but not the other.
  4. Caching issues: The collections count might be cached and not reflecting a recently deleted collection.
  5. System collections: Shopify sometimes has system-generated collections that count toward the total but aren’t returned in normal queries.

To troubleshoot, I’d recommend:

  1. Try a query that explicitly requests both smart and custom collections
  2. Check for any recently deleted collections that might still be counted
  3. Review your Shopify admin panel to see if there’s another collection you’re not aware of
  4. Add fields to your query to get collection IDs and types to identify what might be missing

Cheers!
Shubham | Untechnickle

Thanks for quick reply.

Hidden or unpublished collections: if collection is not published then it would also be ignored in counting.

Permission/visibility issues: I have only assigned one collection to product that is visible on storefrotn

Smart collections vs. custom collections: you can see in screenshot there is no smart collection

Caching issues: I have tried this after some time probably 1 hr later, so there should not be the cache issue, also when I add new custom collection using collection page, the counting again increased by 1 even the the collection is not assigned to product yet

I see the issue now! The screenshot shows you have two collections in your Shopify admin: “test” with 0 products and “Home page1” with 4 products. This explains the totalCount of “2” in your second GraphQL query.

Looking at your original screenshots, I noticed something important - your first query is only returning “Home page1” even though you requested up to 250 collections. The “test” collection isn’t appearing in the nodes response.

This is likely because your GraphQL query is specifically tied to a product (note the product(id:…) part), and it’s only returning collections that are associated with that specific product. Since your “test” collection has 0 products (as shown in your admin panel), it doesn’t appear in the product-specific query.

The second query’s totalCount is correctly showing “2” because it’s counting all collections regardless of product association.

To fix this discrepancy, you have a few options:

  1. Use a direct collections query instead of going through a specific product if you want to see all collections.
  2. Try a query like this to see all collections:
{
  collections(first: 10) {
    edges {
      node {
        id
        title
        productsCount
      }
    }
    pageInfo {
      hasNextPage
    }
  }
}
  1. If you specifically need to query collections through products, understand that you’ll only get collections associated with that product.

The behavior is actually consistent with how Shopify’s GraphQL API works - when querying through a product, you’re only getting collections linked to that product, but the totalCount is giving you the store-wide number.

Hope that helps :slightly_smiling_face:

Shubham | Untechnickle

Hi Partner,

I want to count and get product collections

See this query, I am getting collection count of specific product:
product(id: “gid://shopify/Product/10537400926511”) {collections(first: 1) {totalCount}}}

see this query I am getting collections of specific products:
product(id: “gid://shopify/Product/10537400926511”) {collections(first: 250) {nodes {title} }}}

Please help if you can

This is likely because your GraphQL query is specifically tied to a product (note the product(id:…) part), and it’s only returning collections that are associated with that specific product. Since your “test” collection has 0 products (as shown in your admin panel), it doesn’t appear in the product-specific query.

pointing out your suggestion, the count query is also specifically tied to a product see product(id:…) part

I understood your answer, but how we can count the product collections if it is giving totalCollection not for specific product