Fork me on GitHub
#pathom
<
2021-04-28
>
bbss18:04:13

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

wilkerlucio21:04:30

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

wilkerlucio21:04:52

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

dehli21:04:39

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

wilkerlucio21:04:33

that’s a valid option 👍

wilkerlucio21:04:53

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

wilkerlucio21:04:00

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

💯 3
bbss03:04:08

Thank you both! ❤️

🙏 6
wilkerlucio02:05:16

@bbss walking the code I remembered another simpler option for this:

(let [env (-> (pci/register
                [foo])
              (update :com.wsscode.pathom3.format.eql/map-select-include
                coll/sconj :tempids))]
  (p.eql/process env [{'(foo {:bar "baz"}) [:value]}]))
one thing to consider there, is that it will affect not just mutations, but any entity that has the :tempids key

bbss02:05:08

Thanks! I can see that being useful.

wilkerlucio02:05:16

@bbss walking the code I remembered another simpler option for this:

(let [env (-> (pci/register
                [foo])
              (update :com.wsscode.pathom3.format.eql/map-select-include
                coll/sconj :tempids))]
  (p.eql/process env [{'(foo {:bar "baz"}) [:value]}]))
one thing to consider there, is that it will affect not just mutations, but any entity that has the :tempids key