Cache never seems to be called

Hi there,

I have an apollo endpoint which users use to search for other users names. I call this inside a NextJS getServersideProps, as follows:

  const { data: users } = await apolloClient.query({
    query: searchUsernameQuery,
    variables: { input: { term, page: parseInt(page) } }

This is then passed into a page route as a prop.

In order to test the cache is working, I added a console log to my backend resolver, searchUsernameQuery which just console logs out the term passed in. My assumption here is that if we searched for “bob” we would see a console log, but if we then searched for “bob” again we wouldn’t see a console log because this would be an identical call and the apollo cache would be hit first.

However, every single time I search for “bob” my backend is hit and I see the console log.

Im therefore assuming my cache is not working and was wondering if I am doing something wrong?

Just to note, I have the following set on my Apollo Server:

    cacheControl: {
      defaultMaxAge: 300 // 5 minutes

I also have the following in my Apollo Client:

export function createApolloClient(initialState = {}) {
  const ssrMode = typeof window === 'undefined'
  const cache = new InMemoryCache({ }).restore(initialState)

  return new ApolloClient({

@alex-r89 it sounds like your client side cache instance isn’t being rehydrated properly. In your browser console, you can always dump the contents of to see the loaded contents of your cache. I would suggest checking that to see if things are being hydrated the way you expect, so they can then be found by future queries.