Fork me on GitHub
#pathom
<
2021-02-25
>
Luan01:02:14

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.

kenny02:02:27

Do you need pathom for this? If not, can you pull the functionality out into a function and call that?

👍 3
wilkerlucio12:02:19

@U01GKAHT163 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)

👍 3
wilkerlucio12:02:32

without context of your application is hard to tell which is more appropriated'

👍 3
Björn Ebbinghaus16:02:11

I use a transformer for things like this

👍 3
mitchelkuijpers16:02:19

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 resolver

wilkerlucio16:02:47

not sure if I understand, complete example?

mitchelkuijpers17:02:29

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

mitchelkuijpers17:02:00

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 ="}}

mitchelkuijpers17:02:30

I expected the string "my param =10000"

wilkerlucio17:02:09

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

wilkerlucio17:02:14

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

wilkerlucio17:02:40

I believe that was the case in Pathom 2 as well, but Fulcro suggested some plugins to make the transfer down

mitchelkuijpers17:02:54

Aah ok I will be calling this from fulcro

mitchelkuijpers17:02:01

I'll play around with this tomorrow thnx Wilker

wilkerlucio17:02:00

@U060GQK8U currently I believe you can make it using the ::pcr/wrap-merge-attribute

wilkerlucio17:02:16

but I also feel this one should be use with some care, because this one happens a lot (every attribute merge)

wilkerlucio17:02:40

so I think for your case a ::pcr/wrap-merge-ident would be more appropriate

wilkerlucio17:02:55

this is an easy add, I'll use the opportunity and work this one later today

wilkerlucio17:02:14

and happy to see you again around here @U060GQK8U 🙂

nivekuil18:02:54

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

nivekuil18:02:21

(basically a quick port of the RAD plugin)

mitchelkuijpers18:02:02

Thnx @U066U8JQJ we were never gone! Still using pathom very happy with it!

😁 3
mitchelkuijpers08:02:11

I 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

wilkerlucio11:02:28

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

wilkerlucio11:02:46

its not lost, but the placement of it is different from what you are expecting

wilkerlucio11:02:41

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

wilkerlucio11:02:48

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

mitchelkuijpers11:02:54

I fixed it now by creating an ident with a map with two ids

mitchelkuijpers11:02:08

Because the actual problem is that I need two ids to get something

wilkerlucio11:02:25

in Pathom 3, placeholders can take params for multiple inputs too

wilkerlucio11:02:53

like: [{(:>/foo {:p1 21 :p2 21412}) [:bar]}]

mitchelkuijpers11:02:55

Yeah that looks cool but we want to call it from Fulcro not sure how good that will work together

wilkerlucio11:02:02

altough I imagine it wouldnt be so nice for Fulcro, yeah

mitchelkuijpers11:02:17

I love how that works though