Fork me on GitHub

Is there a way to load a global resolver that resolves to a value (as opposed to an entity)?

Jakub Holý (HolyJak)15:09:21

No, Pathom resolvers must return a map, so {:answer 42}


But that's what I mean -- :answer is not resolving to a map (e.g. {:answer {:number/id #uuid "xxxx", :number/value 42}}), it resolves to a value 42.


I know that if it was resolving to a map with an ID, I could simply do (df/load! this :answer this) and modify the :query of Mycomp accordingly.


But when it's resolving to a value, what should I put on the second argument of df/load!?


For example, I have a global resolver that resolves :answer to 42. Now I want to load :answer to my component:

(defsc MyComp [_ {:keys [answer]}]
  {:ident (fn [] [:component/id :my-comp])
   :query [:answer]
   :componentDidMount (fn [this] (df/load! <HOW DO I WRITE THIS TO LOAD :answer?>))}
  (div (str answer)))


It would be great if the second argument of df/load! (`server-property-or-ident`) can be set to nil to indicate that the query [:answer] is sent at the root level, rather than under another field (i.e., a server property or ident)

Jakub Holý (HolyJak)20:09:23

Here is the solution: So this works

(pc/defresolver forty-two 
  [_ _]
  {::pc/input  #{}
   ::pc/output [:answer]}
  {:answer 42})
(df/load! app/app :answer nil)
This will send to Pathom the query [:answer] and get the response {:answer 42}

👍 2

Right now, my workaround is to load under another global resolver that does return an entity. For example, if I have the global resolver :current-session, then I use (df/load! this :current-session this), even though :answer has nothing to do with :current-session.


Not sure if there's a better way.

Tom H.04:09:02

Hey folks, does anyone have an example that uses Pathom 3 as a fulcro remote?


if you use Pathom on the server side, you can follow the example here:

pathom 2

if you wanna use Pathom directly from CLJS, here is an example remote helper:

(defn pathom-remote [request]
  {:transmit! (fn transmit! [_ {::txn/keys [ast result-handler]}]
                (let [ok-handler    (fn [result]
                                        (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]
                                        (result-handler (assoc error-result :status-code 500))
                                        (catch :default e
                                          (js/console.error e "Error handler for remote failed with an exception."))))
                      key           (-> ast :children first :key)
                      entity        (some-> ast :children first :query meta :pathom/entity)
                      ident-ent     {key (conj entity key)}]
                  (-> (p/let [res (request
                                    (cond-> {:pathom/ast ast}
                                      entity (assoc :pathom/entity ident-ent)))]
                        (ok-handler {:transaction (eql/ast->query ast)
                                     :body        res}))
                      (p/catch (fn [e]
                                 (js/console.error "Pathom Remote Error" e)
                                 (error-handler {:error e}))))))})

💯 2

request in this case is a boundary interface fn:

👍 2

Excuse the basic question, @U066U8JQJ, but what is the namespace p in p/let and p/catch above? Also trying to hook up a Fulcro remote with Pathom 3 from CLJS.


the p is related to the Promesa library, its a dependency of Pathom 3, so you probably already have it around, under promesa.core

👍 1

I am using a remote to call asynchronous JS functions in Fulcro, but I am not sure how to get a channel from a Pathom parser, in order to pass my results from my async resolvers. Any ideas?

Jakub Holý (HolyJak)19:09:25

I do not follow. What has your presumably custom remote has to do with Pathom and why do you need (core.async?) channel from pathom? Is Pathom running on backend or fronted?


Front end. My custom remote uses pathom to parse incoming requests. I would like my resolvers to return asynchronously


It is modeled after the remote used in the book.

Jakub Holý (HolyJak)20:09:12

Pathom has multiple parsers including -parallel and -async, at least some of them do that

Jakub Holý (HolyJak)20:09:22 > If you want to write parsers to run in Javascript environments, then async operations are the norm. The async parser is a version of the parser were you can return core.async channels from the readers instead of raw values. This allows for the creation of parsers that do network requests or any other async operation.


Thanks @U0522TWDA ! I did not see the example.