pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
hadils 2021-05-23T14:56:06.006700Z

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 (get-item "@user-id"))]
      {:user-id user-id})))

(def resolvers [index-explorer save-user-id get-user-id])

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

(comment
  (go (prn (async/&lt;! (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

2021-05-23T16:14:13.006800Z

You need to put your quote outside the paren I think

2021-05-23T16:14:55.007Z

Right now your symbol is trying to do a map lookup

hadils 2021-05-23T17:27:14.007400Z

Thank you @codonnell!

👍 1