This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-27
Channels
- # announcements (3)
- # aws (7)
- # babashka (11)
- # beginners (96)
- # clojure (15)
- # clojure-europe (9)
- # clojure-germany (2)
- # clojure-italy (1)
- # clojure-nl (3)
- # clojure-poland (3)
- # clojure-serbia (1)
- # clojurescript (13)
- # depstar (28)
- # fulcro (34)
- # graalvm (5)
- # honeysql (5)
- # malli (11)
- # off-topic (27)
- # pathom (9)
- # polylith (74)
- # portal (10)
- # re-frame (13)
- # releases (1)
- # ring (8)
- # shadow-cljs (3)
- # spacemacs (10)
- # tools-deps (8)
Hello! I have a question about pathom2's cache. I have a resolver that returns a vector of items. How can I associate those items with an ident so that I don’t have to look them up again if they’ve already been returned? The basic code looks like:
(pc/defresolver items-resolver
[_]
{::items [{::item {::id 0 ::name "foo" ::depends-on nil}}
{::item {::id 1 ::name "bar" ::depends-on {::id 0}}}]})
(pc/defresolver item-resolver
[{id ::id}]
;; Don't want this to have to be called for the `depends-on` key in my query below
{::item (get-from-db)})
(pc/defresolver item-normalizer
[{item ::item}]
{::id ...
::name ...
::depends-on ...})
;; Query
[{::items [::name {::depends-on [::name]}]}]
;; Expected result
{::items [{::name "foo" ::depends-on nil}
{::name "bar" ::depends-on {::name "foo"}}]}
Pathom doesn't have the concept of normalization like that
one thing you can do is manually pre-fill the cache for a resolver you expect is going to be called
the batch works like this too, you have to add a cache entry on the resolver with the exact input and output you want (the input must have only the keys required by the resolver, otherwise the cache will miss)
this line has an example of pathom caching: https://github.com/wilkerlucio/pathom/blob/master/src/com/wsscode/pathom/connect.cljc#L837
Thanks! I think pathom caching can solve what I'm trying to accomplish. Will give that a go!
What do the e
and p
stand for in the snippet you pasted? I’m running into some issues so my guess is that I’m not exactly supplying the data properly. Currently I have:
(p/cached env ['my.resolver/symbol {:user/id "foo"} {}]
{:user/output "bar"})
where {:user/id "foo"}
is the input into the supplied symbol and {:user/output "bar"}
is what it returns. If I don’t wrap the output in a channel I get an error with take!