# Why does Apollo Client throw "Missing field" errors when calling writeQuery with incomplete data?

**URL:** <https://community.apollographql.com/t/why-does-apollo-client-throw-missing-field-errors-when-calling-writequery-with-incomplete-data/2232>\
**Category:** Client SDKs\
**Tags:** client, web\
**Created:** [December 14, 2021, 4:05pm UTC](https://community.apollographql.com/t/why-does-apollo-client-throw-missing-field-errors-when-calling-writequery-with-incomplete-data/2232 "2021-12-14T16:05:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joepvl](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/joepvl/32/1474_2.png) [@joepvl](https://community.apollographql.com/u/joepvl)\
**Post date:** [December 14, 2021, 4:05pm UTC](https://community.apollographql.com/t/why-does-apollo-client-throw-missing-field-errors-when-calling-writequery-with-incomplete-data/2232/1 "2021-12-14T16:05:36Z")

</div>

I’m using Apollo Client 3.4.x. When calling `writeQuery` and passing data that’s missing fields specified in the query, I would expect Apollo Client to just not care about those missing fields and leave them in the cache as-is, while updating the fields that _are_ specified. In practice it does actually update the fields, but in development mode (`if ( __DEV__ )`) it also throws an error saying `Missing field 'x' while writing result /* passed value(s), stringified */`. The error is thrown here: [apollo-client/src/cache/inmemory/writeToStore.ts at b214dd1d31cdfe6b5477bb5887a7d9615a302b27 · apollographql/apollo-client · GitHub](https://github.com/apollographql/apollo-client/blob/b214dd1d31cdfe6b5477bb5887a7d9615a302b27/src/cache/inmemory/writeToStore.ts#L348-L363)

Meanwhile, in the docs, under [Editing existing data](https://www.apollographql.com/docs/react/caching/cache-interaction/#editing-existing-data) it says

> If you include a field in `query` but don’t include a _value_ for it in `data` , the field’s current cached value is preserved.

Am I misreading this? It reads to me like passing only the fields you want to write is completely supported behavior and shouldn’t be causing errors to be thrown, even if they are only thrown in development mode. At most it should be a warning with some kind of caveat like “if you only meant to update the data, you can safely ignore this warning”.

---

<div class="post-metadata">

**Author:** ![Yasir\_Rafiq\_Malik](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/yasir_rafiq_malik/32/2726_2.png) [@Yasir\_Rafiq\_Malik](https://community.apollographql.com/u/Yasir_Rafiq_Malik)\
**Post date:** [July 18, 2022, 12:30pm UTC](https://community.apollographql.com/t/why-does-apollo-client-throw-missing-field-errors-when-calling-writequery-with-incomplete-data/2232/2 "2022-07-18T12:30:00Z")

</div>

Did you managed to solve this ?

---

<div class="post-metadata">

**Author:** ![LarsEjaas](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/larsejaas/32/2744_2.png) [@LarsEjaas](https://community.apollographql.com/u/LarsEjaas)\
**Post date:** [July 21, 2022, 9:08pm UTC](https://community.apollographql.com/t/why-does-apollo-client-throw-missing-field-errors-when-calling-writequery-with-incomplete-data/2232/3 "2022-07-21T21:08:23Z")

</div>

I ran into the same issue.  
I have no workaround for using the `writeQuery` method. Instead, I use the `updateQuery` method if I need to partially overwrite a query.

Example:

```auto
const setThemeName = (name: ThemeNames): void => {
  cache.updateQuery({ query: Get_App_ThemeDocument }, (data) => ({
    appTheme: {
      __typename: "AppTheme",
      name: name,
      mode: data?.appTheme?.mode,
    },
  }));
};

```

data is the current data for this query in the cache, and you can then pass in the existing data on fields you do not want to overwrite.

---

<div class="post-metadata">

**Author:** ![i8e4](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/i8e4/32/3718_2.png) [@i8e4](https://community.apollographql.com/u/i8e4)\
**Post date:** [January 13, 2023, 10:53am UTC](https://community.apollographql.com/t/why-does-apollo-client-throw-missing-field-errors-when-calling-writequery-with-incomplete-data/2232/4 "2023-01-13T10:53:56Z")

</div>

Any update on this???
