hi everyone. does anyone know how to dispatch mutations in re-graph
?
I have no mutations in my example, but should be about the same as query or subscription.
(re-frame/reg-event-fx
::mutate
interceptors
(fn [{:keys [db dispatchable-event]} [query variables callback-event :as event]]
(let [query (str "mutation " (string/replace query #"^mutation\s?" ""))]
(cond
(get-in db [:websocket :ready?])
(let [query-id (internals/generate-query-id)]
{:db (assoc-in db [:subscriptions query-id] {:callback callback-event})
::internals/send-ws [(get-in db [:websocket :connection])
{:id query-id
:type "start"
:payload {:query query
:variables variables}}]})
(:websocket db)
{:db (update-in db [:websocket :queue] conj dispatchable-event)}
:else
{::internals/send-http [(:http-url db)
{:request (:http-parameters db)
:payload {:query query
:variables variables}}
(fn [payload]
(re-frame/dispatch (conj callback-event payload)))]}))))
thank you, that’s helpful!