# Apollo v4 updateQuery

**URL:** <https://community.apollographql.com/t/apollo-v4-updatequery/9534>\
**Category:** Client SDKs\
**Created:** [October 30, 2025, 11:51am UTC](https://community.apollographql.com/t/apollo-v4-updatequery/9534 "2025-10-30T11:51:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![raxell](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/raxell/32/6407_2.png) [@raxell](https://community.apollographql.com/u/raxell)\
**Post date:** [October 30, 2025, 11:51am UTC](https://community.apollographql.com/t/apollo-v4-updatequery/9534/1 "2025-10-30T11:51:04Z")

</div>

Hi, new question about the migration to v4 (react).  
I have some places when i use `updateQuery`, e.g.

```auto
        updateQuery((state) => ({
          ...state,
          myField: [
            ...state.myField,
            {
              // new element
            },
          ],
        }))

```

`state` is now a `DeepPartialObject` and I’m getting type errors for things not being iterable, being undefined, etc…  
Any hint on how to handle this? At the moment I would prefer to not refactor it using `update` in `useMutation` or similar methods.  
Is the merge still shallow (so I need to spread the inner fields), or handled differently?

---

<div class="post-metadata">

**Author:** ![lenz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lenz/32/4007_2.png) [@lenz](https://community.apollographql.com/u/lenz)\
**Post date:** [October 30, 2025, 11:54am UTC](https://community.apollographql.com/t/apollo-v4-updatequery/9534/2 "2025-10-30T11:54:31Z")

</div>

That first argument unfortunately always could be incomplete, but it was never reflected in the types.

You can be safer by using the second argument:

```auto
updateQuery((_, {complete, previousData}) => {
  if (complete) {
    // in here, `previousData` has the same shape that your `state` previously had
  } else {
    // you never handled this case before, as it was hard to detect in AC3 - this will need some new logic
  }
}

```

---

<div class="post-metadata">

**Author:** ![raxell](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/raxell/32/6407_2.png) [@raxell](https://community.apollographql.com/u/raxell)\
**Post date:** [October 30, 2025, 12:13pm UTC](https://community.apollographql.com/t/apollo-v4-updatequery/9534/3 "2025-10-30T12:13:07Z")

</div>

Thank you  
So if `complete` is false, `previousData` is a partial object or `undefined`?  
In the former case I could just spread the partial `previousData` by accessing fields with optional chaining and it should be equivalent to the previous implementation, correct?

---

<div class="post-metadata">

**Author:** ![lenz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lenz/32/4007_2.png) [@lenz](https://community.apollographql.com/u/lenz)\
**Post date:** [October 30, 2025, 12:17pm UTC](https://community.apollographql.com/t/apollo-v4-updatequery/9534/4 "2025-10-30T12:17:23Z")

</div>

If `complete` is `false`, it could be pretty much anything, undefined (which will show as `{}` though, not `undefined`), shallow partial, or even deep partial - you don’t have a guarantee that it’s “shallow complete”, you could also have overlapping data from another query in the cache that has queried for different fields on the same entities, maybe with nuanced changes nested deeper.
