pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
2021-06-04T04:04:08.040500Z

I suspect I'm missing something silly here, but how do I do the initial entity lookup? My query looks like this:

[{[:user/id #uuid "5f3bf49f-36fa-41a8-88dd-09ca67f8392f"]
  [:db/id]}]
I'm pretty sure I want a resolver (not a reader), but not positive. I expected it to convert [:user/id #uuid "5f3bf49f-36fa-41a8-88dd-09ca67f8392f"] to {:user/id #uuid "5f3bf49f-36fa-41a8-88dd-09ca67f8392f"} internally and trigger my {::pc/input #{:user/id} ::pc/output [:db/id]} resolver, but it never runs. Is there a simple example of this somewhere? I can't find it in the docs.

Björn Ebbinghaus 2021-06-04T08:22:11.041800Z

You have to use an ident reader for pathom to understand idents. E.g. pc/open-ident-reader

wilkerlucio 2021-06-04T13:21:47.042Z

can you please share the parser setup? the query looks correct, maybe there is some setup missing

2021-06-04T13:36:15.042200Z

Yeah, here's the whole thing.

2021-06-04T13:41:06.042600Z

I should mention, this is pathom 2.2.31.

wilkerlucio 2021-06-04T13:45:02.042800Z

one minor error in the example code is that you define p and try to call parser

wilkerlucio 2021-06-04T13:45:36.043Z

this is working here (minor changes to your code, so I don't depend on datascript/datomic):

(pc/defresolver user-resolver
  [{:keys [db]} {:keys [user/id]}]
  {::pc/input  #{:user/id}
   ::pc/output [:db/id]}
  (println :user-resolver) ;; never prints
  {:db/id (get-in db [:user/id id])})

(def p
  (p/parser
    {::p/env     {::p/reader [p/map-reader
                              pc/reader2
                              pc/open-ident-reader
                              p/env-placeholder-reader]}
     ::p/plugins [(pc/connect-plugin {::pc/register [user-resolver]})
                  p/error-handler-plugin]}))
(comment
  (let [db {}]
    (p {:db db}
      [{[:user/id #uuid "5f3bf49f-36fa-41a8-88dd-09ca67f8392f"]
        [:db/id]}]))
  )

wilkerlucio 2021-06-04T13:45:43.043200Z

(let [db {}]
    (p {:db db}
      [{[:user/id #uuid "5f3bf49f-36fa-41a8-88dd-09ca67f8392f"]
        [:db/id]}]))
:user-resolver
=> {[:user/id #uuid"5f3bf49f-36fa-41a8-88dd-09ca67f8392f"] #:db{:id nil}}

2021-06-04T13:46:11.043500Z

Oh geez. 🤦

2021-06-04T13:48:03.043700Z

I guess I was missing something silly. Thanks for taking a look.

wilkerlucio 2021-06-04T13:48:24.043900Z

no worries, glad to help