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.
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
- Include the type's key field (
id) in both the query and any mock. - Make mocked results match the operation's selection set exactly.
- For keyless types, configure
keyFields: falseso no key is expected.
// 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.
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.