apollographql / apollo-kotlin

:rocket:  A strongly-typed, caching GraphQL client for the JVM, Android, and Kotlin multiplatform.
https://www.apollographql.com/docs/kotlin
MIT License
3.73k stars 653 forks source link

Disabling normalisation in apollo graph QL Normalisation cache #5366

Open maksood1920 opened 10 months ago

maksood1920 commented 10 months ago

Question

Hi All,

I have setup normalised cache for my graphql. I observed as the response size increases caching seems ineffective. E.g - For the response size of 257, the latency from cache goes to 15 ms(p90). However If I cache the response with simple guava cache then the latency falls back to 0.05ms.

I overridden the fromFieldArguments method of CacheKeyResolver as well but didn't help much either.

Data -

  "offers({"namespace":"Google","offerFilter":{"Or":[{"offerId":"0P827IH1466"},{"offerId":"0P47IJ53218"}]},"offerVendingStrategy":{"revisionFilterStrategy":"FetchAllRevisions"}}).0.partnerTerms" : {
    "__typename" : PartnerTerms
    "partnerName" : null
    "partnerOfferId" : null
  }

I want to have CacheKeyResolver on individual offerId but offerId is present in the offerFilter and that is not allowing me to get cache key for individual record. I tried HTTP cache on top of normalised cache but that is disk based storage and that is not acceptable,

I want to disable normalisation and for my apollo client but something similar to in memory guava cache. Is there any way I can achieve this ?

martinbonnin commented 10 months ago

I don't think there's a native built-in way to do this but you could certainly build your own from the ApolloInterceptor API.

You can copy/paste most of the HTTP cache implementation and replace the DiskLruHttpCache with a Guava cache, or make this configurable when setting up the HTTP cache.

That'd actually be an awesome contribution if you feel like it.

martinbonnin commented 9 months ago

@maksood1920 did you find a solution to this this problem eventually?