Fork me on GitHub
#pathom
<
2019-07-21
>
jose09:07:45

I'm still trying to make the pathom-viz query editor a standalone app. I notice that the simple-parser-demo card expects a local Pathom parser, but I already have a http server listening for Pathom queries, so I'm trying to make the requests to the server. I think I should update this: https://github.com/wilkerlucio/pathom-viz/blob/abb4006be4181ebf4c803a1e07edbe4a8ff790c1/src/core/com/wsscode/pathom/viz/workspaces.cljs#L31-L34 to make http requests, but I'm lost, not sure how. Any suggestions?

wilkerlucio12:07:15

hello @jlle, from the snippet you sent I'm remembering that the query runner uses a different remote name, that's this pv.query-editor/remote-key, did you tried settings this remote to be your remote?

jose14:07:54

@wilkerlucio you mean something like

:networking
{pv.query-editor/remote-key
 (p.network/pathom-remote "")}
?

wilkerlucio14:07:40

close, but you have to use the regular fulcro network if you want to use the standard HTTP remote, the pathom-remote is a wrapper to turn local async parsers in remotes

wilkerlucio14:07:17

oh, sorry, I just realized it will require some more effort to wrap the http call

wilkerlucio14:07:55

there is a problem in the current implementation, you actually have to use an async parser interface to use the network it provides

wilkerlucio14:07:59

but its not so bad, you can wrap the remote with a parser interface, which is: [env tx] => channel

wilkerlucio14:07:14

let me try to get a demo, that will help updating the docs also

wilkerlucio14:07:56

or, do a fetch call from the parser interface

wilkerlucio14:07:07

@jlle something like this:

wilkerlucio14:07:52

(defn transit-read [x]
  (-> (transit/read (transit/reader :json) x)))

(defn transit-write [x]
  (-> (transit/write (transit/writer :json) x)))

(defn http-request-parser [url]
  (fn [env tx]
    (go-catch
      (let [{::p.http/keys [body]}
            (<? (p.http/request {::p.http/driver       p.http.fetch/request-async
                                 ::p.http/url          url
                                 ::p.http/content-type ::p.http/transit+json
                                 ::p.http/method       ::p.http/post
                                 ::p.http/headers      {}
                                 ::p.http/form-params  (transit-write tx)}))]
        (transit-read body)))))

; networking
:networking
{pv.query-editor/remote-key
 (p.network/pathom-remote
   (pv.query-editor/client-card-parser (http-request-parser "")))}

jose15:07:03

@wilkerlucio thanks, it looks better, I see that pathom queries are done to the server 🙂 For some reason the results are not displayed on the card. But I can see the proper response on the chrome devtools network tab. I don't have time now, but I'll try to debug it later