This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-20
Channels
- # admin-announcements (1)
- # announcements (1)
- # beginners (115)
- # calva (31)
- # cider (25)
- # clj-kondo (47)
- # cljdoc (23)
- # cljs-dev (5)
- # clojars (1)
- # clojure (60)
- # clojure-australia (1)
- # clojure-europe (23)
- # clojure-nl (3)
- # clojure-norway (2)
- # clojure-spec (3)
- # clojure-uk (18)
- # clojurescript (49)
- # community-development (1)
- # cursive (4)
- # datahike (2)
- # datascript (3)
- # datomic (36)
- # deps-new (2)
- # emacs (2)
- # events (9)
- # fulcro (6)
- # graphql (2)
- # gratitude (13)
- # holy-lambda (1)
- # introduce-yourself (10)
- # macro (2)
- # malli (5)
- # meander (9)
- # news-and-articles (5)
- # nextjournal (1)
- # off-topic (32)
- # pathom (17)
- # pedestal (13)
- # polylith (4)
- # protojure (4)
- # reagent (4)
- # sci (27)
- # shadow-cljs (2)
- # show-and-tell (2)
- # specter (3)
- # tools-deps (7)
- # xtdb (16)
Can nested entities “see” the outer context while in a pathom process? I thought I saw this in use at some point, but it’s not working now.
(p.eql/process
{}
{:root/some-data :some-data
:nest {}}
[:root/some-data
{:nest [:root/some-data]}])
=> {:root/some-data :some-data, :nest {}}
no, they cant, if you want that the parent must forward that data down
copy it over at the higher resolver
in the resolver of :root/some-data, get the input and copy into the items, makes sense?
;; I'm not sure how to extend this resolver to use a pathom parameter
(pco/defresolver foo
[{id :a/id}]
{::pco/output [:a/b :a/c]}
(get {1 {:a/b 1 :a/c 2}} id))
;; first, it seems necessary to extend the number of arguments it takes to get the env variable
(pco/defresolver foo1
[env {id :a/id}]
{::pco/output [:a/b :a/c]}
(get {1 {:a/b 1 :a/c 2}} id))
;; as an aside its odd that even though the first argument to p.eql/process is the id, it now comes as the second argument
(p.eql/process (pci/register foo1)
{:a/id 1})
;; The real issue how ever is how to pass a pathom parameter now
(p.eql/process (pci/register foo1)
{:a/id 1}
;; i'm assuming this should be of the grammar here
)
;; But it's not clear how or what. First lets use our param instead of the input
(pco/defresolver foo2
[env {id :a/id}]
{::pco/output [:a/b :a/c]}
(get {1 {:a/b 1 :a/c 2}} (-> env pco/params :param/id)))
(p.eql/process (pci/register foo2)
{:a/id 1}
);; => nil
(p.eql/process (pci/register foo2)
{:a/id 1} ;; ignoring this on purpose
;; if we look at this example
;; (p.eql/process env ['(::todos {::todo-done? false})])
;; then we should pass a vector, but the second argument is a list with one key. What does that mean?
;; in our example here, the output isn't one map but two, so where does the "with param"/param go?
;; we trying something random
['(:a/b {:param/id 1})]
;; it doesn't work
);; => nil
hello, can you tell a bit more concretely what you looking for? I'm not sure if I get what you trying to do yet
about the signature, think this way, resolvers *always* take 2 parameters, the thing is that the defresolver
macro will fill in if env is missing, but if you need env (and you do need it for params), then you add it before
I think the following example may help with it:
(pco/defresolver param-item [env {:keys [id]}]
{::pco/output [:a :b]}
{:a (pco/params env)
:b (pco/params env)})
(comment
(p.eql/process
(pci/register param-item)
{:id 1}
['(:a {:foo "bar"})
':b]))
outputs:
=> {:a {:foo "bar"}, :b {:foo "bar"}}
when doing params with resolvers that have multiple outputs, remember they will share the params
would love some feedback on how we can improve the docs for it
@U066U8JQJ i'm mostly trying to learn pathom, so this is very helpful. Interestingly, the code i linked actually now returns the correct result. Which makes me believe my repl had ended up in some corrupted state. Such is life? I'm hesitant to recommend changes to docs without a better understanding. but here are a few things that caused some confusion. It's unclear what arguments defresolver takes. Ideally i could look at the function signature and at least have idea. I'm not sure why are we passing what seems to be a global param attached to any particular "attribute" (e.g (':b {:foo "bar"}) , please correct if me if this is the wrong term). In this example it's taking the first instance of the param and ignoring the second. (p.eql/process (pci/register param-item) {:id 1} ['(:b {:foo "car"}) '(:a {:foo "bar"}) ]);; => {:b {:foo "car"}, :a {:foo "car"}} Why not have it as a completely separate argument? I suspect there is a good reason it just hasn't clicked for me yet. Again, my goal was just to learn. My primary confusion was because as the oringal example shows, i was getting nil as where the same code now evals to {:a/b 1} the expected output. Ty for taking the time to answer my questions.
params are per resolver, it makes more sense if understand how the planning works (https://pathom3.wsscode.com/docs/planner), it goes scanning the query figuring out what resolvers get called, when it sees an attribute it adds the params to that resolver call (that's why it comes from the env, the pco/params helper will find the node representing that resolver execution and pull the params definition from there)
that said, params are mostly used in resolvers with a single list in the output, to do things like pagination or some basic filtering, if the param is intended for something else, you should consider making it an input instead, inputs are a preferable way in general to give more data then params is (since they can participate in the resolution process, meaning their implementation remains open and can evolve)