How can we get the count of total results in GraphQL | Community
Skip to main content
October 1, 2024
Solved

How can we get the count of total results in GraphQL

  • October 1, 2024
  • 4 replies
  • 3216 views

Hi,

I want to use GraphQL for searching and building a listing page with pagination. As I explored, I understand that GraphQL supports offset, limit, sorting etc. but I couldn't find a way to get the total number of results to achieve pagination with page number.

It would be really helpful if anyone can suggest how can we achieve it using GraphQL.

 

Thanks in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by RiteshY18

@rajeevku  then would suggest having pagination login in Java script and letting JS decide behavior based on the response object

4 replies

RiteshY18
Community Advisor
Community Advisor
October 5, 2024

@rajeevku consider below

GraphQL in AEM provides support for two types of pagination:

RajeevKuAuthor
October 7, 2024

Thank for the reply @riteshy18 .

I already had a look on these two types and these two does not gives the total count to build a pagination based on page number. For example, I want to show the page number 1-5 and if user clicks on a number, then corresponding results are fetched and displayed.

RiteshY18
Community Advisor
RiteshY18Community AdvisorAccepted solution
Community Advisor
October 9, 2024

@rajeevku  then would suggest having pagination login in Java script and letting JS decide behavior based on the response object

kautuk_sahni
Community Manager
Community Manager
October 9, 2024

@rajeevku Did you find the suggestion helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!

Kautuk Sahni
Anny0505
Community Advisor
Community Advisor
November 23, 2024

 

  • Calculate the total count of items matching the search criteria.
  • Fetch the paginated results using the provided offset and limit.

 

Aditya_Chabuku
Community Advisor
Community Advisor
December 5, 2024

Hi @rajeevku ,

 

Did you got solution for this problem? Please let the community know if so, it would help others to learn from that knowledge.

If not, check this site for some idea about Pagination using GraphQL https://hygraph.com/learn/graphql/pagination?form=MG0AV3 

 

Happy Coding,

 

Thanks,Aditya Chabuku
New Member
February 16, 2025

Seems not all the features of this documentation are present on AEM, since I get:

Field 'pageSize' in type 'PageInfo' is undefined"