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({
ssrMode,
cache
})
}