# Fetchmore and deletion ( Apollo Client cache policy)

**URL:** <https://community.apollographql.com/t/fetchmore-and-deletion-apollo-client-cache-policy/5393>\
**Category:** Client SDKs\
**Tags:** client, web\
**Created:** [January 5, 2023, 2:49pm UTC](https://community.apollographql.com/t/fetchmore-and-deletion-apollo-client-cache-policy/5393 "2023-01-05T14:49:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Conny\_Gu](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/conny_gu/32/3568_2.png) [@Conny\_Gu](https://community.apollographql.com/u/Conny_Gu)\
**Post date:** [January 5, 2023, 2:49pm UTC](https://community.apollographql.com/t/fetchmore-and-deletion-apollo-client-cache-policy/5393/1 "2023-01-05T14:49:24Z")

</div>

Hi all,

I am using `fetchMore` from the `useQuery()` hook to achieve some **click to load more** functionality.

For example, I want to make a long job list and I can also delete the job items.

Here is what I do according to apollo client pagination core api and the cache documentaiton:

```auto
//in JobList.tsx

const {data, loading, error, fetchMore} = useQuery(GetAllJobsCursorPaginated)

```

so I define the `merge` function in `typePolicy` in `cache`, somehow like this:

```auto
// in client.ts

const cache = new InMemoryCache({
  typePolicies: {
    Query: {
      fields: {    
        getAllJobsCursorPaginated: {
          keyArgs: false,
          merge(existing, incoming) {
              .... // implementing merging logic
                return [...existing, ...incoming] // this is for fetchMore
          }
       ...

```

But in the meanwhile, but I also want to delete some records, so I use a delete Mutation, and also set a update function for the

```auto
//in JobList.tsx

...
const [deleteJob] = useMutation(DeleteJob)
...

const onClickDelete = async (_id: string) => {
  await deleteJob({
    variables: {_id},
    update: (cache) => {
       const data = ... // implementing the deletion logic
      cache.writeQuery({query: getAllJobsCursorPaginatedQuery, data})
    }
  })
}

```

However, the problem is with the deletion, it always works as `fetchMore`: take the result after deletion and append it to “existing”…

How can I configure the `deleteJob` Mutation correctly?

Thanks for any suggestion!

---

<div class="post-metadata">

**Author:** ![JeffAuriemma](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/jeffauriemma/32/2845_2.png) [@JeffAuriemma](https://community.apollographql.com/u/JeffAuriemma)\
**Post date:** [January 5, 2023, 9:50pm UTC](https://community.apollographql.com/t/fetchmore-and-deletion-apollo-client-cache-policy/5393/2 "2023-01-05T21:50:44Z")

</div>

Hi @Conny_Gu 👋 would `cache.modify` suit your use case better? From the [docs](https://www.apollographql.com/docs/react/caching/cache-interaction/#using-cachemodify):

> - Like `writeQuery` and `writeFragment`, `modify` triggers a refresh of all active queries that depend on modified fields (unless you override this behavior by passing `broadcast: false`).
> - _Unlike_ `writeQuery` and `writeFragment`:
> - `modify` circumvents any [`merge` functions](https://www.apollographql.com/docs/react/caching/cache-field-behavior/#the-merge-function) you’ve defined, which means that fields are always overwritten with exactly the values you specify.
> - `modify` _cannot_ write fields that do not already exist in the cache.

This would allow you to bypass the `merge` function and allow you to define another function to filter out deleted entries from your `getAllJobsCursorPaginated` list. Hope that helps!

---

<div class="post-metadata">

**Author:** ![Conny\_Gu](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/conny_gu/32/3568_2.png) [@Conny\_Gu](https://community.apollographql.com/u/Conny_Gu)\
**Post date:** [January 6, 2023, 1:00pm UTC](https://community.apollographql.com/t/fetchmore-and-deletion-apollo-client-cache-policy/5393/3 "2023-01-06T13:00:03Z")

</div>

Hi @JeffAuriemma , thanks! thanks! thanks! Cache.modify is exact what I need! 🥰
