This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-27
Channels
- # announcements (8)
- # architecture (3)
- # aws (18)
- # beginners (96)
- # bristol-clojurians (3)
- # calva (15)
- # cider (7)
- # clj-kondo (8)
- # clojure (135)
- # clojure-denmark (1)
- # clojure-dev (14)
- # clojure-europe (37)
- # clojure-italy (9)
- # clojure-nl (14)
- # clojure-sanfrancisco (1)
- # clojure-spec (1)
- # clojure-uk (54)
- # clojurescript (27)
- # core-async (243)
- # cursive (28)
- # data-science (6)
- # datomic (33)
- # fulcro (25)
- # graalvm (24)
- # hoplon (2)
- # instaparse (12)
- # jackdaw (1)
- # java (21)
- # juxt (12)
- # meander (10)
- # nyc (4)
- # off-topic (6)
- # om (3)
- # pathom (17)
- # perun (1)
- # re-frame (29)
- # reitit (4)
- # rum (3)
- # shadow-cljs (119)
- # spacemacs (31)
- # xtdb (14)
In the docs I can see how to send queries to graphql without fulcro but I don't understand what facilities pathom offers for parsing the graphql response
@yenda welcome 🙂 can you tell more about what you mean on parsing graphql response?
So I have a re-frame app and I would like to use pathom without fulcro, since I already have a graphql backend I started with the front end, using pathom to query the local state. Now I'd like to explore using it to manage it as well. Currently I have graphql queries as string that I send with axios and denormalize the data "manually". I am playing with query->graphql
and it seems to work fine with some tuning to query the endpoint, and I'm wondering if there is an equivalent graphql->query
to convert the response to EQL.
@yenda gotcha, yeah, the query->graphql
is something pathom uses internally, I should rename this page here: https://wilkerlucio.github.io/pathom/v2/pathom/2.2.0/graphql/fulcro.html
altough its named fulcro, this works for anything (just ignore the fulcro remote and UI parts, all the rest should be same, the parser configuration is what matters to you here)
if you go with the connect part, you can even extend your GraphQL things on the pathom side (created dynamic computations on top of what graphql provides)
Ok I'm exploring this, I think that my biggest pain point is to figure how to fill the ident-map, because the endpoint uses attributes like "user_id" "user_name" which translates to "user/id", "user/name" in the app
I had to do the following to generate a valid query:
(defn js-name [k]
(if (qualified-keyword? k)
(str (namespace k) "_" (-> k
name
pg/camel-case))
k))
(defn ident-transform [[key value]]
(let [fields [(str (namespace key) "_" (-> key
name
pg/camel-case))]
value (if (vector? value) value [value])]
(if-not (= (count fields) (count value))
(throw (ex-info "The number of fields on value needs to match the entries" {:key key :value value})))
{::pg/selector (-> (namespace key) (clojure.string/split #"\.") last)
::pg/params (zipmap fields value)}))
#_(println (pg/query->graphql [{[:user/id "5503438a-583f-11ea-99f8-0242c0a82002"]
[:user/id :user/name :user/photo :user/is-current-user-following]}]
{::pg/ident-transform
ident-transform ::pg/js-name js-name}))
This is what I'm trying atm:
(def remote-gql
{::pcg/url ""
::pcg/prefix "remote"
::pcg/mung clj->gql
::pcg/demung gql->clj
::pcg/ident-map {"user" {"user_id" :remote.user/id}}
::p.http/driver request-async})
(take! (pcg/load-index remote-gql) #(reset! indexes %))
(def remote-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.http/driver request-async}
::p/mutate pc/mutate-async
::p/plugins [(pc/connect-plugin {; we can specify the index for the connect plugin to use
; instead of creating a new one internally
::pc/indexes indexes})
p/error-handler-plugin
p/trace-plugin]}))
(take! (remote-parser {} [{[:remote.user/id "5503438a-583f-11ea-99f8-0242c0a82002"]
[:remote.user/id :remote.user/name :user/photo]}]) println)
and I get {[:remote.user/id 5503438a-583f-11ea-99f8-0242c0a82002] {:remote.user/id 5503438a-583f-11ea-99f8-0242c0a82002, :user/photo :com.wsscode.pathom.core/not-found, :remote.user/name :com.wsscode.pathom.core/not-found}}
request-async
is just the regular one but I added a print to see which request is sent, seems like it doesn't send any