Cache corruption (fails silently) when mutation fields don't match query?
See original GitHub issueIntended 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:
- Created 6 years ago
- Reactions:2
- Comments:8 (3 by maintainers)
Top GitHub Comments
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.
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.
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