Is there any way to check whether graphql query result is served from cache?

Hi,

We are using apollo graphql in-memory cache. There is a requirement from our client, we want to log the info log when the graphql API is called. We are able to log this in console when the query is executed for first time but after this since the query result is cached and served from cache for subsequent requests we can’t log these requests, is there any way to log if the query result is served from cache.

Regards,
Suresh

Hi @sureshdarisa - I would recommend logging through the Apollo Link chain, to make sure you’re only logging requests when they’re being fired off to the network. You can learn more about writing a custom Apollo Link here: Apollo Link overview - Apollo GraphQL Docs

Hi @hwillson

Thanks for the reply.

Actually we are using Apollo GraphQL Server V2 and we are responsible for exposing only server side GraphQL API (only query no mutations). Request is reaching our GraphQl service from frontend like below.

frontend → AggregateService → API g/w → GraphQL API service

So frontend is not making call directly to our graphQL api service via gateway. It is coming from aggregator service which is written in spring boot. Is there anyway we can do the logging at server side in this scenario.

Regards,
Suresh