Skip to content

Commit

Permalink
prove that query ids can be provided or not, relates to #78
Browse files Browse the repository at this point in the history
  • Loading branch information
oliyh committed Jan 16, 2023
1 parent 250f2eb commit abffdc0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Dispatch the `init` event to bootstrap it and then use the `:subscribe`, `:unsub

;; perform a query, with the response sent to the callback event provided
(re-frame/dispatch [::re-graph/query
{:id :my-query-id ;; unique id for this query
{:id :my-query-id ;; unique id for this query (optional, used for deduplication)
:query "{ things { id } }" ;; your graphql query
:variables {:some "variable"} ;; arguments map
:callback [::on-thing]}]) ;; callback event when response is recieved
Expand Down
24 changes: 24 additions & 0 deletions test/re_graph/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,30 @@
(deftest named-http-parameters-test
(run-http-parameters-test :service-a))

(deftest http-query-with-id-test
(let [dispatch (partial dispatch-to-instance nil)]
(run-test-sync
(let [expected-http-url "http://foo.bar/graph-ql"
call-count (atom 0)]
(init nil {:http {:url expected-http-url}
:ws nil})
(testing "Request is completed"
(re-frame/reg-fx
::internals/send-http
(fn [{:keys [request]}]
(is request)
(swap! call-count inc)))
(dispatch [::re-graph/query {:id "query-1"
:query "{ things { id } }"
:variables {:some "variable"}
:callback [::on-thing]}])
(dispatch [::re-graph/mutate {:id "mutation-1"
:query "don't care"
:variables {:some "variable"}
:callback [::on-thing]}])

(is (= 2 @call-count)))))))

(defn- call-instance [instance-id f]
(fn [opts]
(f (if instance-id
Expand Down

0 comments on commit abffdc0

Please sign in to comment.