Fork me on GitHub
#pathom
<
2020-07-28
>
jackson13:07:52

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

wilkerlucio15:07:05

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

jackson16:07:59

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.

jackson16:07:58

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

jackson17:07:20

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

jackson17:07:38

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

🎉 3