Clojure,re-graph成功地从graphql获取了数据,但回调没有';t激活
因此,我使用0.1.11版本的re-graph,并尝试从端点获取数据。获取数据后,我检查了浏览器中的“网络”选项卡,找到了预期的数据,之后它应该会激活我的回调函数,但它似乎不起作用(但有时它起作用,在刷新页面几次后,它就不再起作用)。这是代码Clojure,re-graph成功地从graphql获取了数据,但回调没有';t激活,clojure,graphql,clojurescript,re-frame,graphqlclient,Clojure,Graphql,Clojurescript,Re Frame,Graphqlclient,因此,我使用0.1.11版本的re-graph,并尝试从端点获取数据。获取数据后,我检查了浏览器中的“网络”选项卡,找到了预期的数据,之后它应该会激活我的回调函数,但它似乎不起作用(但有时它起作用,在刷新页面几次后,它就不再起作用)。这是代码 ;; how I init re-graph (rf/dispatch [::re-graph/init ::conf/graphql-client-name {:ws-url url
;; 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,但它的工作方式与上面的代码相同。因此我设法找到了我自己问题的答案。似乎应用程序数据库尚未正确初始化,所以我修复了该问题,一切正常。希望它能帮助解决这个问题的人