Skip to content
Latchkey

Apollo "Missing field X while writing result" in CI

When Apollo normalizes a query result into InMemoryCache, every selected field (and the configured key field such as id) must be present. A response missing one logs "Missing field X while writing result" and can leave the cache incomplete.

What this error means

A query or a mocked response triggers "Missing field \"id\" while writing result {...}" in the console, and dependent components read undefined from the cache.

Apollo Client
Missing field 'id' while writing result {
  "__typename": "User",
  "name": "Ada"
}

Common causes

The result omits the cache key field

InMemoryCache normalizes by id/_id (or a custom keyField). A response that selects the type but not its key cannot be normalized cleanly.

A mock response narrower than the query

A MockedProvider mock returns fewer fields than the operation selects, so the cache write reports the missing ones.

How to fix it

Return every selected field, including the key

  1. Include the type's key field (id) in both the query and any mock.
  2. Make mocked results match the operation's selection set exactly.
  3. For keyless types, configure keyFields: false so no key is expected.
JavaScript
// mock must include id and every selected field
{ request: { query: GET_USER, variables: { id: '1' } },
  result: { data: { user: { __typename: 'User', id: '1', name: 'Ada' } } } }

Declare types that have no id

For value objects without a stable key, tell the cache not to expect one.

JavaScript
new InMemoryCache({
  typePolicies: { Geo: { keyFields: false } },
});

How to prevent it

  • Always select the key field for every cached object type.
  • Keep mocks aligned with the exact selection set under test.
  • Configure keyFields:false for genuinely keyless value types.

Frequently asked questions

What causes ""Missing field while writing result""?
InMemoryCache normalizes by id/_id (or a custom keyField). A response that selects the type but not its key cannot be normalized cleanly.
How do I fix "Missing field while writing result"?
Return every selected field, including the key

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card