pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
Luan 2021-02-25T01:56:14.010500Z

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.

wilkerlucio 2021-02-25T12:59:19.012300Z

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

πŸ‘ 1
wilkerlucio 2021-02-25T12:59:32.012500Z

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

πŸ‘ 1
BjΓΆrn Ebbinghaus 2021-02-25T16:16:11.012700Z

I use a transformer for things like this

πŸ‘ 1
kenny 2021-02-25T02:17:27.012Z

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

πŸ‘ 1
mitchelkuijpers 2021-02-25T16:33:19.014Z

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

mitchelkuijpers 2021-02-26T08:41:11.019800Z

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

wilkerlucio 2021-02-26T11:39:28.020Z

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

wilkerlucio 2021-02-26T11:39:46.020200Z

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

wilkerlucio 2021-02-26T11:40:41.020400Z

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

mitchelkuijpers 2021-02-26T11:41:22.020700Z

Ah ok

wilkerlucio 2021-02-26T11:41:48.020900Z

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

mitchelkuijpers 2021-02-26T11:41:54.021100Z

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

mitchelkuijpers 2021-02-26T11:42:08.021300Z

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

wilkerlucio 2021-02-26T11:42:25.021500Z

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

wilkerlucio 2021-02-26T11:42:53.021700Z

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

mitchelkuijpers 2021-02-26T11:42:55.021900Z

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

wilkerlucio 2021-02-26T11:43:02.022100Z

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

mitchelkuijpers 2021-02-26T11:43:17.022300Z

I love how that works though

wilkerlucio 2021-02-25T16:47:47.014400Z

not sure if I understand, complete example?

mitchelkuijpers 2021-02-25T17:02:29.014600Z

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

mitchelkuijpers 2021-02-25T17:03:00.014800Z

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

mitchelkuijpers 2021-02-25T17:03:30.015Z

I expected the string "my param =10000"

wilkerlucio 2021-02-25T17:04:09.015200Z

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

wilkerlucio 2021-02-25T17:05:14.015400Z

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

wilkerlucio 2021-02-25T17:06:40.015600Z

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

mitchelkuijpers 2021-02-25T17:08:54.015800Z

Aah ok I will be calling this from fulcro

mitchelkuijpers 2021-02-25T17:10:01.016Z

I'll play around with this tomorrow thnx Wilker

wilkerlucio 2021-02-25T17:11:00.016200Z

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

wilkerlucio 2021-02-25T17:11:16.016400Z

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

wilkerlucio 2021-02-25T17:11:40.016800Z

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

wilkerlucio 2021-02-25T17:11:55.017Z

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

wilkerlucio 2021-02-25T17:13:14.017300Z

and happy to see you again around here @mitchelkuijpers πŸ™‚

nivekuil 2021-02-25T18:15:54.017600Z

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

nivekuil 2021-02-25T18:16:21.017800Z

(basically a quick port of the RAD plugin)

mitchelkuijpers 2021-02-25T18:59:02.018Z

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

😁 1