Apollo cache js object transformation on read

hey all

i’m using apollo graphql react sdk in my clojurescript project

i’m having an issue with the caching mechanism and the transformation of js object to cljs objects.

basically, in cljs i’m applying the function “js→clj” to the values return from apollo.

the issue happens when a query (watch query subscribe) is returned from cache and skips my js→clj call, and then i’m dealing with js object in my cljs env

i have tried writing a link for it that maps js object to cljs, but then apollo can’t write it to cache (i guess because it is looking for some key that changed its name)

so the question is, how can i modify the reads from all of the responses (including cache) and apply a tranformation function on them?

thanks

Hmm, a link would be too early.

I don’t really know Closure, so please forgive me if I make very wrong assumptions here - but I believe it should look something like this:

In Apollo Client 3

client.watchQuery(...).map(js2Clj).subscribe(yourCallback)

or in Apollo Client 4

client.watchQuery(...).pipe(map(js2Cli)).subscribe(yourCallback)

Of course you could also call js2Cli in yourCallback every time. You just have to be aware that you will get a new object again and again, and you’ll have to convert each of these new objects.

ohh great! i didn’t notice that the result of watchQuery is an actual observable!

thank you very much!

if it interests you, that how it looks

(-> client (.watchQuery options) (.map js->clj) (.subscribe my-callback))