This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-03
Channels
- # announcements (3)
- # asami (4)
- # aws (1)
- # babashka (22)
- # beginners (111)
- # calva (3)
- # cider (1)
- # clj-kondo (55)
- # clj-on-windows (9)
- # cljsrn (1)
- # clojure (13)
- # clojure-europe (35)
- # clojure-losangeles (3)
- # clojure-nl (2)
- # clojure-norway (2)
- # clojure-spec (2)
- # clojure-uk (5)
- # clojurescript (51)
- # conjure (5)
- # cursive (5)
- # datascript (1)
- # datomic (27)
- # deps-new (8)
- # depstar (41)
- # emacs (4)
- # fulcro (24)
- # graphql (4)
- # gratitude (8)
- # helix (36)
- # jobs (2)
- # leiningen (2)
- # lsp (11)
- # off-topic (24)
- # pathom (23)
- # pedestal (2)
- # polylith (27)
- # re-frame (12)
- # reagent (7)
- # reitit (1)
- # releases (3)
- # remote-jobs (1)
- # rewrite-clj (4)
- # sci (1)
- # shadow-cljs (27)
- # spacemacs (12)
- # tools-deps (31)
- # web-security (2)
Is there a way to load a global resolver that resolves to a value (as opposed to an entity)?
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)
Here is the solution: https://github.com/fulcrologic/fulcro/blob/develop/src/main/com/fulcrologic/fulcro/data_fetch.cljc#L233 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}
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
.
if you use Pathom on the server side, you can follow the example here: https://pathom3.wsscode.com/docs/tutorials/serverless-pathom-gcf
![pathom](https://emoji.slack-edge.com/T03RZGPFR/pathom/65d3a7297fdf0a0f.png)
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]
(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 (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}))))))})
request
in this case is a boundary interface fn: https://pathom3.wsscode.com/docs/eql/#boundary-interface
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
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?
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
Pathom has multiple parsers including -parallel and -async, at least some of them do that
You have seen https://github.com/fulcrologic/fulcro/blob/develop/src/main/com/fulcrologic/fulcro/networking/mock_server_remote.cljs#L30 I assume? But this is the result of the whole parser, not a single resolver
https://blog.wsscode.com/pathom/v2/pathom/2.2.0/core/async.html
> 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.