Get total number of products in collection with Storefront API GraphQL

La_Colonia
Shopify Partner
12 1 3

I've been browesing several topics in this forum but I haven't found any answer.

We are doing a React webapp which uses the Storefront API with GraphQL. On collection page we would like to list 10 products and display a pagination index, eg: "1, 2, 3 ... last"

Unfortunately I havent found any way to get the total number of products per collection. 

It'd be great to have a totalCount like this http://graphql.org/learn/pagination/#complete-connection-model but it isn't implemented. How can I achieve the same thing?

Replies 7 (7)

Hafros
Shopify Partner
2 0 0

There is no totalCount parameter in the SDK. Just use hasNextPage

La_Colonia
Shopify Partner
12 1 3

That's what we're doing temprarely. Having a totalCount would be great, otherwise you have to do convoluted workaround to get that information.

Hafros
Shopify Partner
2 0 0

I do not know what your visual solutions are for pagination. Show please, can we find a solution

La_Colonia
Shopify Partner
12 1 3

 

That's the one.

If there are more than 6 pages it becomes 1 2 3 ... 7 8 9. 

Without totalCount I can only use the NEXT button

La_Colonia
Shopify Partner
12 1 3

I'm thinking of using Shopify Admin API to retrieve the total number with this https://help.shopify.com/api/reference/product#count

babyt
Shopify Partner
1 0 1

I know this is an old post, but you can use the filters to sum up the available + unavailable products to get the total count for the collection

 

```

query {

 // collection query

  products(

    filters {

      values {

         id

         label

         count

      }

    }

  )

}

HerclasNido
Shopify Partner
1 0 0

Well thought. Thank you, you saved me! 🙏