pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
MatthewLisp 2021-06-08T15:00:13.054300Z

Hi everyone! I'm taking a look at the docs/guide regarding Pathom plugins, and i'm seeing this snippet

; define the extension wrapper fn
(defn protect-attributes-wrapper [mse]
 (fn [env source {:keys [key] :as ast}]
   (if (and (contains? source key)
            (contains? protected-attributes key))
 ; the output of this extension must be a map entry or nil
 ; a vector with two elements would also work, but creating a map entry is
 ; more efficient
 (coll/make-map-entry key ::protected-value)
 (mse env source ast))))
I'm wondering about the comment that states the output of this extension must be a map entry or nil However i see that the output is actually a call to the original function, in this example called mse What i'm missing here?

2021-06-08T15:08:03.056600Z

Hi @matthewlisp, the call to (mse env source ast) is in the else leg of the condition.

2021-06-08T15:08:49.057500Z

so in that sample (coll/make-map-entry key ::protected-value) itโ€™s called if something needs to be hidden, if not continue with the normal execution: (mse env source ast)

MatthewLisp 2021-06-08T15:12:40.059Z

wow, right, the comment lines made me forget that we were inside an if statement haha, thanks

๐Ÿ‘ 1
2021-06-08T17:52:59.063900Z

Does anyone know where I could find a simple example of how to connect pathom to datomic (or any other database)? I've tried doing it in a resolver, but it doesn't seem to recurse into child entities so my other resolvers don't get triggered.

(pc/defresolver bill-id-resolver
  [{:keys [db]} {:keys [bill/id]}]
  {::pc/input #{:bill/id}
   ::pc/output all-datomic-attributes}
  ;; {:db/id (:db/id (d/entity db [:bill/id id]))}
  ;; (select-keys (d/entity db [:bill/id id]) all-datomic-attributes)
  (d/pull db all-datomic-attributes [:bill/id id]))
Then I tried in a reader, but it's only getting triggered for the initial lookup-ref and not attributes in the associated pull expression.
(defn datomic-reader
  [{:keys [db ast] :as env}]
  (let [lookup-ref ((juxt p/ident-key p/ident-value) env)
        k (:dispatch-key ast)
        e (d/entity db lookup-ref)
        v (get e k)]
    (println lookup-ref k e v)
    (if v
      {k v}
      ::p/continue)))
Here's the parser I'm using for the reader version. The last-update-t-resolver is just a simple resolver that makes derived data. It works just fine in other parsers.
(def registry
  "All the resolvers to register with the parser."
  [#_bill-id-resolver
   last-update-t-resolver])

(def parser
  (p/parser
   {::p/env     {::p/reader [;; pass through values from the original entity map
                             p/map-reader
                             ;; look up most values in datomic
                             datomic-reader
                             ;; use resolvers for data that doesn't exist yet
                             pc/reader2
                             pc/open-ident-reader
                             ]}
    ::p/plugins [(pc/connect-plugin {::pc/register registry})
                 p/error-handler-plugin]}))

wilkerlucio 2021-06-09T15:13:28.068600Z

reader is a low level abstraction, the resolvers are the correct layer to do that

1
2021-06-08T22:36:11.064700Z

Oops, forgot to include how I'm calling it:

(parser {:db (d/db conn)}
          [{[:ti.bill/id #uuid "799ce7c1-cade-4ecc-8a89-a1df186d724e"]
            [:db/id
             :ti.bill/pro]}])