pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
dehli 2021-03-27T11:44:18.065800Z

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"}}]}

wilkerlucio 2021-03-27T17:39:44.072Z

Pathom doesn't have the concept of normalization like that

wilkerlucio 2021-03-27T17:40:01.072600Z

one thing you can do is manually pre-fill the cache for a resolver you expect is going to be called

wilkerlucio 2021-03-27T17:40:44.074Z

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)

wilkerlucio 2021-03-27T17:44:08.074400Z

this line has an example of pathom caching: https://github.com/wilkerlucio/pathom/blob/master/src/com/wsscode/pathom/connect.cljc#L837

dehli 2021-03-29T20:25:25.079400Z

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!

dehli 2021-03-29T20:27:56.079600Z

I see that e is basically input which matches what I’m doing and p are params so it must be my output that is formatted incorrectly which also matches the behavior I’m seeing with a take! error

dehli 2021-03-29T20:48:19.079900Z

I think I got it! I needed to use p/cached-async instead! 🎉