# Cursor Based Pagination caching

**URL:** <https://community.apollographql.com/t/cursor-based-pagination-caching/9174>\
**Category:** Client SDKs\
**Created:** [June 11, 2025, 2:28pm UTC](https://community.apollographql.com/t/cursor-based-pagination-caching/9174 "2025-06-11T14:28:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrennenRocks](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/brennenrocks/32/6130_2.png) [@BrennenRocks](https://community.apollographql.com/u/BrennenRocks)\
**Post date:** [June 11, 2025, 2:28pm UTC](https://community.apollographql.com/t/cursor-based-pagination-caching/9174/1 "2025-06-11T14:28:48Z")

</div>

I have implemented cursor based pagination and its working as expected for my first call through `useBackgroundQuery` and `useReadQuery`. When I call `fetchMore` it will appropriately call the resolver with the `after` marked and it will return the next batch of data. But then it calls the resolver with the original variables again from `useBackgroundQuery` and my data stays with the first batch of data.

This is my merge function

```ts
  cache: new InMemoryCache({
    typePolicies: {
      Query: {
        fields: {
          notes: {
            keyArgs: false,
            merge(existing = { pageInfo: {}, edges: [] }, incoming, { args, mergeObjects }) {
              if (args?.pagination?.after) {
                const result = {
                  pageInfo: mergeObjects(existing.pageInfo, incoming.pageInfo),
                  edges: [...existing.edges],
                };

                if (!incoming.edges) {
                  return result;
                }

                result.edges.push(...incoming.edges);
                return result;
              }

              return incoming;
            },
          },
        },
      },
    },
  }),

```

I see this merge correctly merging the 2 results yet its still making the 2nd call and only ever returning the first batch

When I use `relayStylePagination()` it will fetch and display the next batch but it doesn’t merge them

Thanks!

---

<div class="post-metadata">

**Author:** ![BrennenRocks](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/brennenrocks/32/6130_2.png) [@BrennenRocks](https://community.apollographql.com/u/BrennenRocks)\
**Post date:** [June 11, 2025, 8:00pm UTC](https://community.apollographql.com/t/cursor-based-pagination-caching/9174/2 "2025-06-11T20:00:27Z")

</div>

I’ve found my issue! I copy and pasted the code from `relayStylePagination` and in my data I’ve realized that I’ve put my `after` and `before` fields inside of a `pagination` object. I had to update the `merge` function to account for this difference.
