![](/img/trans.png)
[英]Connecting re-graph graphql client for clojurescript to lacinia-pedestal graphql server
[英]Clojure, re-graph fetched data from graphql successfully, but callback didn't activate
所以我使用重新圖形版本 0.1.11 並嘗試從端點獲取數據。 獲取數據后,我在瀏覽器中檢查了網絡選項卡,然后我發現了預期的數據,它應該激活我的回調 function,但它似乎不起作用(但有時它起作用,刷新頁面幾次后它不起作用' t 再次工作)。 這是代碼。
;; how I init re-graph
(rf/dispatch [::re-graph/init
::conf/graphql-client-name
{:ws-url url
:http-url url
:ws-reconnect-timeout 500
:resume-subscriptions? true}])
(re-frame.core/reg-event-fx
::fetch-expected-data
(fn [cofx event]
(let [app-db (:db cofx)
some-params (-> event second (cljs.core/js->clj :keywordize-keys true))
token (-> app-db (lens/get-in (auth-db/lens-token :group-level-x)))]
(re-frame.core/dispatch
[:re-graph.core/query
::conf/graphql-client-name
"query findExpectedData($query: FetchExpectedDataInput!, $token: String!) {
findExpectedData(query: $query, token: $token){
value1
value2
...
}
}"
{:query some-params
:token token}
;; this is where the problem occurs
;; even though i found the data in the network tab, but
;; this callback doesn't seem to work (sometimes it works sometimes it doens't)
[::fetched-data-completed]]))))
(re-frame.core/reg-event-fx
::fetched-data-completed
(fn [cofx [_ {:keys [data errors] :as payload}]]
(let [app-db (:db cofx)
error-message (-> errors :errors first :message)]
(if (or (nil? errors) (empty? errors))
(do (bla bla when success))
(pr error-message)))))
我被這個問題困擾了幾個月。 也許是因為我同時獲取了很多數據? 或者可能是其他任何人都知道的東西? 順便說一下,我使用的是 defmacro 的實際代碼,但它的工作方式與上面的代碼相同。
所以我設法找到了我自己問題的答案。 似乎 app-db 沒有正確初始化,所以我解決了這個問題,一切正常。 希望它可以幫助解決這個問題的人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.