InMemoryCache debug/error logging?

Is there a way to make InMemoryCache log errors or other debugging statements?

I’m trying to troubleshoot a problem which I believe is happening in the caching layer (InMemoryCache). I suspect there may be a problem with my field policies or some other issue with the shape of the data that is causing the internal state of the cache to fail to update correctly. This is a paginated query (using fetchMore).

After instrumenting my code a little, I’ve been able to determine that, upon calling fetchMore to retrieve the next page of results, the actual query to the server is succeeding and returning the expected data. I’ve also confirmed that relevant field policy methods (read merge etc) are being called as expected. However, my application code (where useQuery is being called) is not seeing the updated results – the hook never “fires”. No errors are showing up anywhere that I can see (console, query results, etc).

I suspect the cache is blowing up at some point attempting to update its internal state, and I’m hoping there’s a way to get some debugging statements, or some kind or error message that might give me a clue as to where my problem might be.

[UPDATE] I’m trying to troubleshoot a bad interaction between two separate queries that fetch overlapping data. My queries all work fine in isolation (with a clean cache), but specific sequences, where one query is updating a cache which contains the results of another query, seems to put the cache into a bad state where the query (or queries) seem to simply not update at all from that point on. These are both reasonably complicated queries, with complicated UI code on top of them. I’m hoping to zero in on the specific node(s) in the graph that’s giving the cache trouble before I start rewriting queries…

You can do

import { setVerbosity } from "ts-invariant";
setVerbosity("debug");

to get more logs out of Apollo Client - maybe you find something that helps you?

Hi @lenz,

Thanks for the tip. Unfortunately that didn’t seem to add any additional output. I did a quick search through the apollo-client source on GitHub and it doesn’t look like there is a lot of logging instrumentation, and none at all in the caching code, so it looks like I’m on my own here :frowning: