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

How can we get the count of total results in GraphQL

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.

RiteshY18
RiteshY18Accepted solution
New Participant
October 9, 2024

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

7 replies

Aditya_Chabuku
New Participant
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,

 

Translate
Thanks,Aditya Chabuku
New Participant
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"

Translate
Anny0505
New Participant
November 23, 2024

 

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

 

Translate
kautuk_sahni
Employee
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!

Translate
Kautuk Sahni
RiteshY18
New Participant
October 5, 2024

@rajeevku consider below

GraphQL in AEM provides support for two types of pagination:

Translate
RajeevKuAuthor
New Participant
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.

Translate
RiteshY18
RiteshY18Accepted solution
New Participant
October 9, 2024

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

Translate