[英]Clojure, re-graph fetched data from graphql successfully, but callback didn't activate
So I use re-graph version 0.1.11 and I try fetching data from the endpoint.所以我使用重新图形版本 0.1.11 并尝试从端点获取数据。 After fetching data, I checked network tab in the browser and I found the expected data after that it should activate my callback function, but it doesn't seem to work (but sometimes it works and after refreshing the page a few times it doesn't work again).
获取数据后,我在浏览器中检查了网络选项卡,然后我发现了预期的数据,它应该激活我的回调 function,但它似乎不起作用(但有时它起作用,刷新页面几次后它不起作用' t 再次工作)。 Here is the code.
这是代码。
;; 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)))))
I'm stuck with this problem for a few months.我被这个问题困扰了几个月。 maybe because I fetch a lot of data at the same time?
也许是因为我同时获取了很多数据? or could be something else anyone knows?.
或者可能是其他任何人都知道的东西? By the way the actual code I use defmacro, but it works the same way as the above code.
顺便说一下,我使用的是 defmacro 的实际代码,但它的工作方式与上面的代码相同。
So I managed to find the answer to my own question.所以我设法找到了我自己问题的答案。 It seems like app-db has not been initialized properly so I fixed that problem and everything works fine.
似乎 app-db 没有正确初始化,所以我解决了这个问题,一切正常。 hope it helps someone who struggle with this problem.
希望它可以帮助解决这个问题的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.