pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
jackson 2020-07-28T13:50:52.365600Z

Is it possible to update the environment from a mutation for a subsequent mutation join?

wilkerlucio 2020-07-28T15:38:05.366200Z

@jackson.reynolds yes, here is an example:

(ns com.wsscode.pathom.union-repro
  (:require
    [clojure.core.async :as async]
    [com.wsscode.pathom.core :as p]
    [com.wsscode.pathom.connect :as pc]))

(pc/defresolver x [env {:keys []}]
  {::pc/output [::x]
   ::pc/cache? false}
  {::x (:x env)})

(pc/defmutation sample-call [env _]
  {}
  {:foo    "bar"
   ::p/env (assoc env :x "meh")})

(def resolver-registry [sample-call x])

(def parser
  (p/parser
    {::p/env     {::p/reader               [p/map-reader
                                            pc/reader2
                                            pc/open-ident-reader
                                            p/env-placeholder-reader]
                  ::p/placeholder-prefixes #{">"}}
     ::p/mutate  pc/mutate
     ::p/plugins [(pc/connect-plugin {::pc/register resolver-registry})
                  p/error-handler-plugin
                  p/trace-plugin]}))

(comment
  (parser {:x "bla"}
    [::x
     {(list `sample-call {}) [::x]}])
  
  ; => {::x         "bla"
  ;     sample-call {::x "meh"}}
  )

jackson 2020-07-28T16:43:59.366300Z

Thanks. That was my first inclination as well but it seems that as soon as I add ::p/env to the return map I get a NullPointerException. I can prn the new environment just fine and I’m not asking to see it in the EQL query. If I add the environment as ::env instead, I don’t get an exception and obviously don’t update the environment; but as soon as I change it to ::p/env I get the exception.

jackson 2020-07-28T16:57:58.366500Z

In fact, I still get {:com.wsscode.pathom.core/reader-error “class java.lang.NullPointerException”} with your example.

jackson 2020-07-28T17:07:20.366800Z

The only main difference I’m seeing is I’m using p/parallel-parser with pc/parallel-reader and pc/mutate-async

jackson 2020-07-28T17:30:38.367Z

Figured it out. Updated from 2.2.20 to 2.2.30 and everything works as expected. Whew

🎉 1