graphql

Bravi 2019-05-12T09:48:14.098700Z

hi everyone. does anyone know how to dispatch mutations in re-graph?

gklijs 2019-05-12T10:12:46.098800Z

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)))]}))))

Bravi 2019-05-12T10:31:20.099Z

thank you, that’s helpful!