This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-08
Channels
- # asami (15)
- # babashka (123)
- # beginners (174)
- # calva (4)
- # cider (6)
- # cljdoc (4)
- # cljs-dev (4)
- # cljsrn (18)
- # clojure (268)
- # clojure-australia (1)
- # clojure-europe (107)
- # clojure-ireland (5)
- # clojure-nl (2)
- # clojure-uk (18)
- # clojured (1)
- # clojurescript (21)
- # conjure (4)
- # cursive (38)
- # data-science (1)
- # datahike (6)
- # datomic (4)
- # events (1)
- # fulcro (9)
- # graalvm (16)
- # helix (6)
- # honeysql (4)
- # instaparse (3)
- # jobs (1)
- # observability (15)
- # pathom (7)
- # pedestal (15)
- # polylith (9)
- # practicalli (1)
- # re-frame (6)
- # remote-jobs (2)
- # specter (7)
- # sql (16)
- # tools-deps (1)
- # vim (5)
- # xtdb (1)
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?Hi @matthewlisp, the call to (mse env source ast)
is in the else leg of the condition.
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)
wow, right, the comment lines made me forget that we were inside an if
statement haha, thanks
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]}))
reader is a low level abstraction, the resolvers are the correct layer to do that