oliyh / re-graph

A graphql client for clojurescript and clojure

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when no argument map is wrote

giovanialtelino opened this issue · comments

Was getting an error on a query that requires no map:

(re-frame/reg-event-fx
  ::get-comment
  (fn [_ [_ comment]]
    {:dispatch [::re-graph/query
                graph/get-comment
                [::result-get-comments]]}))

TypeError: s.replace is not a function

(re-frame/reg-event-fx
  ::get-comment
  (fn [_ [_ comment]]
    {:dispatch [::re-graph/query
                graph/get-comment
                {}
                [::result-get-comments]]}))

With the empty map it works fine.
I would like to propose a extra check after the query modifier at ::mutate ::query and ::subscribe:

[query (str "query " (string/replace query #"^query\s?" ""))
variables (if (nil? variables) {} variables)]

Is it a good idea?

Hi,

I understand why this would be a nice simplification, but unfortunately the signature of these event handlers is already quite complicated: [query-id query variables callback-event :as event]

You'll notice query-id is there, which is also optional. In fact, there is yet another which is a name for the re-graph instance. All this code exists just to try to sort out the arguments: https://github.com/oliyh/re-graph/blob/master/src/re_graph/internals.cljc#L30-L72

So while this might be a nice change it is practically quite hard to implement, and therefore unlikely to be done. I also think a fixed (or at least fewer) arity is clearer and easier to remember and reminds the user that variables are there to be used, rather than manipulating the query string itself.