Fork me on GitHub
#pathom
<
2021-06-04
>
bmaddy04:06:08

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 Ebbinghaus08:06:11

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

wilkerlucio13:06:47

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

bmaddy13:06:15

Yeah, here's the whole thing.

bmaddy13:06:06

I should mention, this is pathom 2.2.31.

wilkerlucio13:06:02

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

wilkerlucio13:06:36

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

wilkerlucio13:06:43

(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}}

bmaddy13:06:03

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

wilkerlucio13:06:24

no worries, glad to help