Fork me on GitHub
#pathom
<
2021-01-28
>
nivekuil13:01:31

the plugins are so much nicer to write in pathom 3!

wilkerlucio14:01:50

thanks 🙂 what change you found made it nicer in your opinion?

nivekuil14:01:59

it's much shorter, for one.

(def mulog-trace-plugin -  {::pc/wrap-resolve -   (fn [resolver] -     (fn [env input] -       (u/trace (-> env ::pc/resolver-data ::pc/sym keyword) -         [] -         (resolver env input)))) -   ::p/wrap-mutate -   (fn [mutate] -     (fn [env k params] -       (let [out (mutate env k params)] -         (cond-> out -           (:action out) -           (update :action -                   (fn [action] -                     (fn [] -                       (u/trace (keyword k) -                         [] -                         (action)))))))))})
vs
(defplugin mulog-trace-plugin   {::pcr/wrap-resolve    (fn [resolver]      (fn [env node]        (u/trace (-> node ::pco/op-name str) []                 (resolver env node))))    ::pcr/wrap-mutate    (fn [mutation]      (fn [env ast]        (u/trace (-> ast :key str) []                 (mutation env ast))))})

nivekuil14:01:05

it generally just feels much smoother to work with operations directly, as you can call them like functions and mutations/resolvers seem to share more structure than in p2

nivekuil14:01:24

more fun to work with means I actually write plugins. for example, I think pc/transform is not in p3 but it was really easy to just write a custom plugin to replace it

nivekuil14:01:56

in general I think a lot of small changes added up to make p3 feel much more streamlined

wilkerlucio17:01:58

thank you very much for the feedback 🙏

wilkerlucio17:01:10

yeah, mutation plugins were a real pain in the ass in Pathom 2

wilkerlucio17:01:42

just one thing to note though, what you get in the plugin isn't the resolver, neighter the mutation

wilkerlucio17:01:53

its the functions that wrap their call inside the runner

wilkerlucio17:01:11

if you want to access the actual resolver or mutation, you must use the node on resolver, and ast + index in the mutation

nivekuil17:01:44

yeah, I figured out something like this: (get-in env [::pci/index-mutations (:key ast) :config]) not sure if it's mentioned in the docs

wilkerlucio17:01:54

no, if you like to add PR is welcome, or I can put in a todo list here

nivekuil08:01:15

probably should be you, I don't know enough about best practices :)