pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
2021-04-28T18:49:13.253200Z

I am returning tempids from one of my mutations with pathom3 but noticed that it's not returning them. I thought that was working earlier but now I am rather confused. Is there a pathom3 equivalent of

::p/env     {::pc/mutation-join-globals [:tempids]}

2021-05-04T02:46:08.280100Z

Thanks! I can see that being useful.

wilkerlucio 2021-04-28T21:11:30.253300Z

not yet, but that’s something I’m interested in making work

wilkerlucio 2021-04-28T21:11:52.253500Z

I think we need a new plugin entry for the planner to make this work

dehli 2021-04-28T21:13:39.253700Z

I solved a similar problem using ::pf.eql/wrap-map-select-entry Here’s a link to the code which I think could work (unless the plugins have changed since I wrote that code) https://github.com/dehli/pathom3-plugins/blob/main/src/main/dehli/pathom3/plugins.cljc#L9-L38

wilkerlucio 2021-04-28T21:46:33.254100Z

that’s a valid option 👍

wilkerlucio 2021-04-28T21:46:53.254300Z

I was playing with one that can be more performant, by manipulating the AST before the whole process happens

wilkerlucio 2021-04-28T21:47:00.254500Z

(defn mutation-join-globals [globals]
  {::p.plugin/id
   `mutation-join-globals

   ::p.eql/wrap-process-ast
   (fn [process]
     (fn [env ast]
       (process env
         (update ast :children
           #(mapv
              (fn [{:keys [type children] :as ast}]
                (if (and (= type :call)
                         (seq children))
                  (update ast :children into (map (fn [k] {:type :prop :dispatch-key k :key k})) globals)
                  ast))
              %)))))})

(pco/defmutation foo []
  {::pco/op-name 'foo}
  {:value   2
   :tempids {1 "meh"}})

(let [env (-> (pci/register
                [foo])
              (p.plugin/register (mutation-join-globals [:tempids])))]
  (meta (p.eql/process env [{'(foo {:bar "baz"}) [:value]}])))

💯 1