Fork me on GitHub
#pathom
<
2020-01-27
>
roklenarcic09:01:10

hm the example here: https://wilkerlucio.github.io/pathom/v2/pathom/2.2.0/graphql/fulcro.html doesn’t seem to work because namespaces like fulcro.client.network don’t exist

Björn Ebbinghaus13:01:12

Hm. The examples are using fulcro 2 ... This needs to be updated. 😉

wilkerlucio14:01:23

@roklenarcic yeah, for F2, I don't have a shared library with that yet, but you can use this (rename the ns to something that makes sense to you):

(ns remote-pathom
  (:require [edn-query-language.core :as eql]
            [com.wsscode.common.async-cljs :refer [<?maybe]]
            [com.fulcrologic.fulcro.algorithms.tx-processing :as txn]
            [cljs.core.async :refer [go]]))

(defn pathom-remote [parser]
  {:transmit! (fn transmit! [_ {::txn/keys [ast result-handler]}]
                (let [edn           (eql/ast->query ast)
                      ok-handler    (fn [result]
                                      (try
                                        (result-handler (assoc result :status-code 200))
                                        (catch :default e
                                          (js/console.error e "Result handler for remote failed with an exception."))))
                      error-handler (fn [error-result]
                                      (try
                                        (result-handler (merge error-result {:status-code 500}))
                                        (catch :default e
                                          (js/console.error e "Error handler for remote failed with an exception."))))]
                  (go
                    (try
                      (ok-handler {:body (<?maybe (parser {} edn))})
                      (catch :default e
                        (js/console.error "Pathom Remote error:" e)
                        (error-handler {:body e}))))))})

souenzzo16:01:50

A Small lib to qualify/unqualify data with #pathom Docs still WIP. https://github.com/souenzzo/eql-as

mss19:01:44

I’m trying to dispatch a server-property load! call in fulcro to a pathom resolver with params. the server property seems to be getting picked up properly, but the params I added in the options map of load! don’t seem to be getting parsed by pathom and fed into my resolver as params. any suggestions for how to debug?

cjmurphy19:01:39

There's a Pathom plugin from Fulcro RAD that will fix this. This one is just slightly altered:

(def query-params-to-env-plugin
  "Adds top-level load params to env, so nested parsing layers can see them."
  {::p/wrap-parser
   (fn [parser]
     (fn [env tx]
       (let [children (-> tx eql/query->ast :children)
             query-params (-> (->> children
                                   (reduce
                                     (fn [qps {:keys [type params] :as x}]
                                       (cond-> qps
                                               (and (not= :call type) (seq params)) (merge params)))
                                     {}))
                              (dissoc :pathom/context))
             env (assoc env :query-params query-params)]
         (parser env tx))))})

🙌 8
cjmurphy19:01:22

Then you can pick up the key query-params from in the env of the resolver you want to see your parameters in.