Fork me on GitHub
#pathom
<
2021-05-23
>
hadils14:05:06

I am using Pathom 2.3.1 with Fulcro and I don't know why my mutations don't work with this parser:

(ns com.yardwerkz.local-store.parser
  (:require
    [com.wsscode.pathom.core :as p]
    [com.wsscode.pathom.connect :as pc]
    [cljs.core.async :as async :refer-macros [go]]
    [com.wsscode.async.async-cljs :refer [go-catch <!p <?]]
    [taoensso.timbre :as log]
    [com.wsscode.pathom.trace :as pt]
    [cognitect.transit :as t]
    ["@react-native-async-storage/async-storage" :default AsyncStorage]))

(defn set-item
  [key item]
  (let [w (t/writer :json)
        enc-item (t/write w item)]
    (.setItem AsyncStorage key enc-item)))

(defn get-item
  [key]
  (let [r (t/reader :json)]
    (.then (.getItem AsyncStorage key) #(t/read r %))))

(defn remove-item
  [key]
  (.then (.removeItem AsyncStorage key)))


;;;;; Resolvers for local-store must be written asynchronously.

(pc/defresolver index-explorer [env _]
  {::pc/input  #{:com.wsscode.pathom.viz.index-explorer/id}
   ::pc/output [:com.wsscode.pathom.viz.index-explorer/index]}
  {:com.wsscode.pathom.viz.index-explorer/index
   (get env ::pc/indexes)})

(pc/defmutation save-user-id [env {:keys [user-id]}]
  {::pc/input  #{:user-id}}
  (log/debug "save-user-id" user-id)
  (go
    (<!p (set-item "@user-id" user-id))))

(pc/defresolver get-user-id [_ _]
  {::pc/output [:user-id]}
  (go
    (let [user-id ("}}
                      ::p/mutate  pc/mutate-async
                      ::p/plugins [(pc/connect-plugin {::pc/register resolvers})
                                   p/error-handler-plugin
                                   p/trace-plugin]}))

(comment
  (go (prn (async/<! (parser {} ('save-user-id {:user-id "c"}))))))
When I put the line from the comment block into my CLJS repl, i get {}. If i put and undefined mutation symbol, I get {} . I would appreciate any help given. Thanks1

codonnell16:05:13

You need to put your quote outside the paren I think

codonnell16:05:55

Right now your symbol is trying to do a map lookup

hadils17:05:14

Thank you @codonnell!

👍 3