Lack of totalProducts param in query response is unbelievable Storefront API

matvance
Shopify Partner
1 0 0

Hi,
I am trying to implement a traditional page-based search results in my custom storefront using react-hydrogen package and GraphQL Storefront API and I face with a ridiculous issue.
Namly, I cannot know how many pages should I render for the user because There is no totalProducts or other simillar number in the pageInfo prop in response when requesting the products connection.

I guess that this is the optimization to speed up request resolving but I wish to notice that forcing developers to make requests for maximum number of products again and again just to count them manually and render the valid pages count is definitely not a optimization.

Looking forward for the response,
Best regards

Reply 1 (1)

Shayne
Shopify Staff
254 20 64

Hi there,

You're right — there's still no endpoint available to get the total product count with the storefront API. I can definitely see how this would be beneficial though ... I'll run the feedback up to the team.

You could feasibly work around this with a fairly simple script (using the Admin API) that did a count using the Admin REST API (server side, not from the client), and then pushed the count into a metafield that you could query with your storefront client. It's not the cleanest solution, but if this is something that you absolutely need, it would work.

We're always looking for ways to improve the experience for developers, thanks for your feedback. We appreciate it!

Shayne | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog