Expand my Community achievements bar.

How can we get the count of total results in GraphQL

Avatar

Level 1

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.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

6 Replies

Avatar

Level 1

Thank for the reply @Rite18 .

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.

Avatar

Level 8

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

Avatar

Administrator

@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

Avatar

Community Advisor

 

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

 

Avatar

Community Advisor

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