6

My re-frame views.cljs has:

(re-frame/dispatch [::re-graph/init
                    {:http-url "https://api.spacex.land/graphql"
                     :ws-url nil
                      :http-parameters {:with-credentials? false}}])

(re-frame/dispatch [::re-graph/query
                    "{ launches { id, mission_name } }"  ;; your graphql query
                    [::update-data]])

My events.cljs has:

(re-frame/reg-event-db
 ::update-data
 (fn [db [_ {:keys [data errors] :as payload}]]
   (-> db
     (assoc :errors errors)
     (assoc :data data))))

But I keep getting this error:

core.cljs:3919 re-frame: no :event handler registered for: undefined

jwesonga
  • 4,249
  • 16
  • 56
  • 83

2 Answers2

4

The solution is to include the nil for the query variables

(re-frame/dispatch
 [::re-graph/query
  "{launches {id, mission_name}}"
  nil
  [:add-launches]])
jwesonga
  • 4,249
  • 16
  • 56
  • 83
2

You should use :events/update-data in views.cljs. The :: refers to the current namespace (:views/update-data), and that event handler is not defined there, but in the events namespace.

Also note that you can use:

(-> db
   (assoc :errors errors
          :data data)))

saves you one assoc.

user2609980
  • 10,264
  • 15
  • 74
  • 143
  • Changed it to: (re-frame/dispatch [::re-graph/query "{ launches { id, mission_name } }" ;; your graphql query [:events/add-launches]])` I still see the same error in the console: **re-frame: expected a vector, but got: ({:data {…}})** **re-frame: no :event handler registered for: undefined** – jwesonga Jun 19 '19 at 20:51