Hi, I am using pathom 2 and I would like to know if there is a way to reuse a resolver inside another. For example I have a resolver that verifies if a user exists and I want to reuse this resolver inside another resolver or mutation.
@cbluan the description that you send is bit smelly for me, if its a generic fn, like Kenny said, you can extract and just a regular fn on those. But another (maybe possible) way to think is that you should create some new attribute, on a new resolver, and re-use this in your other resolvers (by attribute name, not resolver name)
without context of your application is hard to tell which is more appropriated'
I use a transformer for things like this
Do you need pathom for this? If not, can you pull the functionality out into a function and call that?
So I am playing around with pathom3 and I noticed when I do a query like this:
[{'([:my/ident 0] {:my-param "10000"})
[:my/property]}]
I lose the parameter :my-param
in the :my/ident
resolverI still find it very weird we lose the eql parameters I can see it in the planner:
[{:type :join,
:dispatch-key :my/ident,
:key [:my/ident 0],
:params {:my-param "10000"},
:query [:my/property],
:children [{:type :prop,
:dispatch-key :my/property,
:key :my/property}]}]}] {:com.wsscode.pathom3.connect.planner/nodes {},
:com.wsscode.pathom3.connect.planner/index-ast {[:my/ident
0] {:type :join,
:dispatch-key :my/ident,
:key [:my/ident
0],
:params {:my-param "10000"},
:query [:my/property],
:children [{:type :prop,
:dispatch-key :my/property,
:key :my/property}]}},
:com.wsscode.pathom3.connect.planner/idents #{[:my/ident
0]}},
[-477873135
its a difference in contexts, consider the params you are proving are the "root level", which is where your ident is, but the properties are a level down
its not lost, but the placement of it is different from what you are expecting
because for pathom, when the subquery is running, that param is part of "parent query", the inside has no visibility about it, its just how it works
Ah ok
in a query that are many plans, if you look at the child plan (for the ident sub-query) this param will not be found anywhere
I fixed it now by creating an ident with a map with two ids
Because the actual problem is that I need two ids to get something
in Pathom 3, placeholders can take params for multiple inputs too
like: [{(:>/foo {:p1 21 :p2 21412}) [:bar]}]
Yeah that looks cool but we want to call it from Fulcro not sure how good that will work together
altough I imagine it wouldnt be so nice for Fulcro, yeah
I love how that works though
not sure if I understand, complete example?
(pco/defresolver
my-ident-by-id
[env _]
{::pco/input [:my/ident]
::pco/output [:my/property]}
{:my/property (str "my param =" (:my-param (pco/params env)))})
(p.eql/process
(pci/register [my-ident-by-id])
[{'([:my/ident 0] {:my-param "10000"})
[:my/property]}])
this gives me:
(p.eql/process
(pci/register [my-ident-by-id])
[{'([:my/ident 0] {:my-param "10000"})
[:my/property]}])
=> {[:my/ident 0] #:my{:property "my param ="}}
I expected the string "my param =10000"
ok, gotcha, this situation is expected, because the param is at the ident level, when its reading data inside :my/property
that params are gone
you have two options here, one is to write a plugin to transfer params down (via env preferably), or put the param in the :my/property
, as:
[{[:my/ident 0] ['(:my/property {:my-param "10000"})]}]
I believe that was the case in Pathom 2 as well, but Fulcro suggested some plugins to make the transfer down
Aah ok I will be calling this from fulcro
I'll play around with this tomorrow thnx Wilker
@mitchelkuijpers currently I believe you can make it using the ::pcr/wrap-merge-attribute
but I also feel this one should be use with some care, because this one happens a lot (every attribute merge)
so I think for your case a ::pcr/wrap-merge-ident
would be more appropriate
this is an easy add, I'll use the opportunity and work this one later today
and happy to see you again around here @mitchelkuijpers π
yeah fulcro needs this plugin as df/load!
can't put params in attr position. this is what I use
{::p.eql/wrap-process-ast (fn [process] (fn [env ast] (-> (assoc env :query-params (reduce (fn [qps {:keys [type params] :as x}] (cond-> qps (and (not= :call type) (seq params)) (merge params))) {} (:children ast))) (process ast))))}
(basically a quick port of the RAD plugin)
Thnx @wilkerlucio we were never gone! Still using pathom very happy with it!