# How can I get the total number of results for use in pagination

**URL:** <https://community.apollographql.com/t/how-can-i-get-the-total-number-of-results-for-use-in-pagination/7046>\
**Category:** Client SDKs\
**Tags:** client, server\
**Created:** [December 11, 2023, 10:15pm UTC](https://community.apollographql.com/t/how-can-i-get-the-total-number-of-results-for-use-in-pagination/7046 "2023-12-11T22:15:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ian](https://avatars.discourse-cdn.com/v4/letter/i/bb73d2/32.png) [@ian](https://community.apollographql.com/u/ian)\
**Post date:** [December 11, 2023, 10:15pm UTC](https://community.apollographql.com/t/how-can-i-get-the-total-number-of-results-for-use-in-pagination/7046/1 "2023-12-11T22:15:41Z")

</div>

I’m trying to get pagination working in my React application. I’ve setup Apollo Server but now I need to get pagination working. I’m looking to use offset-based pagination.

I have a couple of questions:

1. When implementing `limit` on the server, do I use it to _ **limit the results returned from the database** _ or should I return the full set of matching results and then _ **limit the results returned from the resolver** _?

2. How can I return the total number of results matching a search query so that I can use it in pagination on the client-side?

3. Do I need to include the `offsetLimitPagination` in the field policy?

Thanks

---

<div class="post-metadata">

**Author:** ![ian](https://avatars.discourse-cdn.com/v4/letter/i/bb73d2/32.png) [@ian](https://community.apollographql.com/u/ian)\
**Post date:** [December 12, 2023, 9:22pm UTC](https://community.apollographql.com/t/how-can-i-get-the-total-number-of-results-for-use-in-pagination/7046/2 "2023-12-12T21:22:49Z")

</div>

I think I’ve figured these questions out now.

1. Results shouldn’t be limited when querying the database. Instead they should be limited in the resolver with slice() used for pagination.

2. I altered my schema to create a new return type:

```js
type PaginatedResults {
    totalCount: Int
    result: [SearchResult]
}

```

I then was able to count the number of results returned from the database and return it with the relevant slice (page) as the result.

1. It seems that `offsetLimitPagination` is required in addition to `fetchMore` to merge pages of results into a single store in the cache.

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:47pm UTC](https://community.apollographql.com/t/how-can-i-get-the-total-number-of-results-for-use-in-pagination/7046/3 "2025-02-06T20:47:53Z")

</div>

Archived on February 6, 2025, 8:47pm UTC


