question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cache corruption (fails silently) when mutation fields don't match query?

See original GitHub issue

Intended outcome:

After applying mutations the cache should be updated and the UX updated reactively.

Actual outcome:

1). The HOC query is re-run but returns no data. There are no errors. The DevTools extension returns the corrects data (from the server), but “load from cache” hangs.

mutate.update is called with the correct data.

When I try to manually query the client form the JS console, I get the error:

  Error: Can't find field project on object (Task/7ee933c7-30cb-e31a-2c11-cd8c16d6b20d)
  ...
  at readStoreResolver (eval at <anonymous> (http://localhost:3000/app/assets/web.bundle.js:1096:1), <anonymous>:49:19)

But Task/7ee933c7-30cb-e31a-2c11-cd8c16d6b20d does indeed exist in the Store (cache) – I can see it in the DevTools extension, but it doesn’t have the project property because the mutation query spec doesn’t include that. Adding this field partially resolves the problem (see part 2).

a). Shouldn’t the cache be merged intelligently? (Possibly related to https://github.com/apollographql/apollo-client/issues/1693)

(In general, it seems to me quite rare that a mutation will return ALL of the fields that are being queried; that would be a big leakage of separation?)

b). If not, can that be done manually (e.g., in mutate.update – it’s not query-specific so I don’t see how currently)?

c). At the very least, the error should not be swallowed (Side note: I’ve lost a lot of time in the past trying to debug errors that have been silently swallowed by Apollo; furthermore, I don’t seem to be able to catch errors that are reported in a global error handler).

NOTE: I’m still trying to isolate a repro. It would be helpful if the missing field warning provided the context.

2). When I add an optimisticResponse, I get the following error after the response is returned from the server (i.e., not when processing the optimistic response):

TypeError: Cannot read property 'variables' of undefined

This happens in the store:

    else if (isMutationResultAction(constAction)) {
        if (!constAction.result.errors) {
            var queryStoreValue = mutations[constAction.mutationId]; // undefined!

since mutations is an empty object at this point (when invoked with the optimisticResponse it has the appropriate value, but the cache is still not updated).

How to reproduce the issue: Query data and then issue Mutations with a different query spec.

    "apollo-client": "^1.2.2",
    "react-apollo": "^1.2.0",

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
richburdoncommented, May 18, 2017

could break existing query observers

Don’t we already deal with this when two queries have different specs for the same item (i.e., I thought they were merged).

Now looking for examples to understand No. 6.

0reactions
Tushantcommented, Jan 19, 2018

I am getting missing field ‘_id’, 'meta;, ‘owner’ etc warning when trying to update optimistically. That means, the server has to anyhow send the meta, owner, comment field in a response in order to work the optimistic update of UI.

Image of warning

Is there no other way to customize the query result while updating the UI ? Here is the full code with the schema for mutation and the response from the server when mutating

https://gist.github.com/SanskarSans/907063ed9a27d3f38f7de25ca4072faf

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL mutations and cache invalidation - Medium
This solution prevents inconsistencies in the mutation results while still relying on the cache in the result query. context. loaders.
Read more >
FMS 15v3 huge issue : Client-Server Cache gets corrupt / out ...
Hi,. Last week, when I installed 15v3, a query that always worked, failed. What was strange is that the backup, launched standalone (not...
Read more >
Embedding Infinispan caches in Java applications
To achieve this, putForExternalRead() acts as a put call that only operates if the key is not present in the cache, and fails...
Read more >
@apollo/client | Yarn - Package Manager
Apollo Client is a fully-featured caching GraphQL client with ... Better handle deferred queries that have cached or partial cached data for them....
Read more >
Errors | urql Documentation
Your queries must always contain a main operation, one of: query, mutation, or subscription. This error occurs when this is missing, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found