Hi everyone,
I have written re-graph <https://github.com/oliyh/re-graph>, GraphQL client
library for re-frame applications that supports
- Subscriptions and queries
- Websocket and HTTP transports
- Apollo-compatible servers like lacinia-pedestal
- Queueing websocket messages until ready
- Websocket reconnection on disconnect
Usage to subscribe, unsubscribe and query is as simple as the following:
(require [re-graph.core :as re-graph]
[re-frame.core :as re-frame])
;; initialise re-graph, possibly including configuration options (see github
readme for details)
(re-frame/dispatch [::re-graph/init {}])
(re-frame/reg-event-db
::on-thing
(fn [db [_ payload]]
;; do things with payload e.g. write it into the re-frame database
))
;; start a subscription, with responses sent to the callback event provided
(re-frame/dispatch [::re-graph/subscribe
:my-subscription-id ;; this id should uniquely identify
this subscription
"{ things { id } }" ;; your graphql query
{:some "variable"} ;; arguments map
[::on-thing]]) ;; callback event when messages are
recieved
;; stop the subscription
(re-frame/dispatch [::re-graph/unsubscribe :my-subscription-id])
;; perform a query, with the response sent to the callback event provided
(re-frame/dispatch [::re-graph/query
"{ things { id } }" ;; your graphql query
{:some "variable"} ;; arguments map
[::on-thing]]) ;; callback event when response is
recieved
re-graph <https://github.com/oliyh/re-graph> takes care of all the
intermediate steps and lets you focus on writing the queries and dealing
with the results.
Thanks to the Walmart crew for lacinia
<https://github.com/walmartlabs/lacinia> and lacinia-pedestal
<https://github.com/walmartlabs/lacinia-pedestal> which enabled my voyage
of GraphQL discovery!
You can find it on GitHub at https://github.com/oliyh/re-graph, issues and
pull requests are welcome.
Oliy
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.