oliyh / re-graph

A graphql client for clojurescript and clojure
460 stars 39 forks source link

Add example how to use for Clojure. #49

Closed gklijs closed 4 years ago

gklijs commented 4 years ago

I tried to use re-graph from Clojure, but could not get it to work. I tried several things, the latest using the 'plain javascript' style.


  (println "data:" data))

(defn init []
  (re-graph/init {:ws-url   "ws://localhost:8888/graphql-ws"
                  :http-url "http://localhost:8888/graphql"})
  (re-graph/query "{all_last_transactions {iban}}" nil on-thing))```
But there doesn't seem to happen much. When I us a key for the init and query it gives an exception: `Host URL cannot be nil`.
gklijs commented 4 years ago

I'm busy hacking something together, making it just Clojure to keep it simple.

oliyh commented 4 years ago

Hi @gklijs

You're not doing anything wrong, the code should be identical to cljs.

You're right, it never becomes 'ready' because of a mistake in the creation of the websocket. I should be able to do a new build soon. Thanks for reporting!

gklijs commented 4 years ago

Probably not only the creation but also how to send the payload, I copied the bit I needed, and made it clojure ony, and now use

(defn- send-ws
  [ws-connection payload]
  (ws/send-msg ws-connection (json/encode payload)))

to send. Turned out for my use case, a load generator, it's easier to work directly with on-receive instead of callback. I will be speaking at GraphQL Summit 30/31 Oktober, mentioning how usefull and easy to use re-graph is.

oliyh commented 4 years ago

Hi,

Yes I found that too. I've made this fix and others relating to http in the latest release 0.1.11-SNAPSHOT.

I would agree that for a performance/load test you might be better off using the underlying websocket directly, re-graph adds some indirection and re-frame in clj is also not designed for performance.

Thanks for reporting this and letting me know about the conference - hope it goes well and I'd be interested to watch your talk after if it's going to be online.

Cheers