No caching showing up in Apollo devtools?

Hi friends, I did a search in the forums but was unable to find an answer.

Basically, I’ve been using the Apollo/Hasura/React combo for a few months now, and am happy with it. Things are functioning, thank God. I can succesfully do queries, mutations, etc. However, I’d like to add caching in order to improve the user experience.

I installed the Apollo dev tools, but even after running various queries, no caching ever shows up under the ‘cache’ header. It remains empty. In fact, queries only show up briefly (when they are in process), then they disappear as soon as the query is completed. Again, no caching or other logging shows as having taken place in the dev tools.

I’m wondering if anyone else has encountered this, and how I can solve the issue? Are my devtools installed correctly? Did I turn off caching somewhere by accident? Below is the client I am using to wrap my root . Everything else, I am taking directly from the Apollo tutorial. I am of the understanding that caching should be automatic, so what is happening here? Thanks in advance…

		link: ApolloLink.from([
			onError(({ graphQLErrors, networkError }) => {
				if (graphQLErrors) {
					LogRocket.captureException(graphQLErrors);
					graphQLErrors.forEach(({ message, locations, path }) =>
						console.error(
							`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
						)
					);
				}
				if (networkError) {
					// localStorage.removeItem('token');
					LogRocket.captureException(networkError);
					console.error(`[Network error]:`, networkError);
				}
			}),
			authMiddleware,
			new RetryLink(),
			new BatchHttpLink({
				uri: `https://brown-mullet-XXX.hasura.app/v1/graphql/`,
				fetch: fetcher,
			}),
		]),
		cache: new InMemoryCache(),
		connectToDevTools: true,
	});

I’m in the same boat… did you figure it out?

Hi! I believe I did, though it wasn’t through Apollo devtools.

If memory serves correctly, Hasura has an option to add “@cached” when defining your query, which allows for caching to take place in your module.

Also, the ApolloClient useQuery hook allows you to set your fetchPolicy as “cache-and-network”, which will give your hook caching capabilities. While I don’t think I was ever able to use DevTools to confirm that these options worked, I definitely saw that they did in fact operate correctly just by running my app.

Anyways, this was all several months ago, so if you have any further questions, I can dig into my code more in the morning (it’s almost midnight here).

Best Regards,

1 Like