oliyh / re-graph

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

Callback event should also be given all the input arguments #89

Open oliyh opened 2 years ago

oliyh commented 2 years ago

It's now given a map with :response key populated, but it might be nice if it also had :id, :query, :variables etc as well, this could potentially save the user piping this stuff around if they need it in the callback handler

toniz4 commented 6 months ago

Even better, It would be nice if it was able to add any arguments to the callback. Kinda like currying the event

(re-frame/reg-event-db
  ::on-thing
  [re-frame/unwrap]
  (fn [db [user-id user {:keys [response]}]]
    (let [{:keys [data errors]} response]
      ;; do things with data e.g. write it into the re-frame database
    )))

(re-frame/dispatch [::re-graph/subscribe
                    {:id        :my-subscription-id
                     :query     "{ things { id } }"
                     :variables {:some "variable"}
                     :callback  [::on-thing 10 {:username "user" :role "admin"}]}])

What do you think? This would unfortunately break the current functionality, but I think it's a nice addition.