Skip to content

Commit

Permalink
Merge pull request #548 from awkay/om-545
Browse files Browse the repository at this point in the history
fixes attempts to merge joins with parameters (which are not mergeable)
  • Loading branch information
swannodette committed Jan 18, 2016
2 parents 6577934 + d05e6ba commit 5b5a6b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/om/next.cljs
Expand Up @@ -1348,7 +1348,7 @@
(if (contains? (:elements-seen res) expr)
res ; eliminate exact duplicates
(update-in
(if (and (join? expr) (not (union? expr)))
(if (and (join? expr) (not (union? expr)) (not (list? expr)))
(let [jk (join-key expr)
jv (join-value expr)
q (or (-> res :query-by-join (get jk)) [])
Expand All @@ -1357,15 +1357,15 @@
(recursion? jv) jv
:else (merge-joins (into [] (concat q jv))))]
(update-in res [:query-by-join] assoc jk nq))
(update-in res [:non-joins] conj expr))
(update-in res [:not-mergeable] conj expr))
[:elements-seen] conj expr)))]
(let [init {:query-by-join {}
:elements-seen #{}
:non-joins []}
:not-mergeable []}
res (reduce step init query)]
(->> (:query-by-join res)
(mapv (fn [[jkey jsel]] {jkey jsel}))
(concat (:non-joins res))
(concat (:not-mergeable res))
(into [])))))

(defn process-roots [query]
Expand Down
19 changes: 19 additions & 0 deletions src/test/om/next/tests.cljs
Expand Up @@ -1125,6 +1125,25 @@
(is (= server-query query))
(is (= full-response (rewrite response)))))

(deftest test-process-roots-preserves-query-parameters
(let [re-rooted-query (with-meta '({:dashboard {:photo [:url]
:comment [:text]}} {:x 1}) {:query-root true})
full-query [:a :b {:ui-key [re-rooted-query]}]
response {:dashboard {:url "http://images.com/x.gif"}}
full-response {:ui-key response}
{:keys [rewrite query]} (om/process-roots full-query)]
(is (= [:a :b re-rooted-query] query))
(is (= full-response (rewrite response)))))

(deftest test-process-roots-preserves-parameters-2
(let [parameters {:user/email "email", :user/password "password"}
fragment (with-meta (list {:auth [:token ]}
parameters)
{:query-root true})
full-query [{:current-login-q [fragment]}]
{:keys [rewrite query]} (om/process-roots full-query)]
(is (= [fragment] query))))

;; -----------------------------------------------------------------------------
;; User Bugs

Expand Down

0 comments on commit 5b5a6b0

Please sign in to comment.