Fork me on GitHub
#fulcro
<
2022-09-18
>
bbss04:09:24

This seems like a bug/limitation of raw for unions:

;;using raw comp
;;[com.fulcrologic.fulcro.raw.components :as comp]

(def union-tree
  {:a/id "a" :a/union [{:b/id "b" :b/name "B"}]})

(defsc B [_ _]
  {:query [:b/id
           :b/name]
   :ident :b/id})

(defsc Union [_ _]
  {:query (fn [] {:b/id (comp/get-query B)})
   :ident :b/id})

(defsc A [_ _]
  {:query [:a/id {:a/union (comp/get-query Union)}]
   :ident :a/id})

(fnorm/tree->db
 A
 union-tree
 true)
;; => {:a/id "a", :a/union [[:b/id "b"]], :b/id {"b" #:b{:id "b", :name "B"}}}

(def b (comp/nc [:b/id :b/name]
                {:ident :b/id}))

(def union (comp/nc {:b/id (comp/get-query b)}
                    {:ident (fn [this props]
                              (println "not called")
                              [:b/id (:b/id props)])}))

(def a (comp/nc [:a/id {:a/union (comp/get-query union)}]))

(= (comp/get-query a) (comp/get-query A))
;; => true

;;however:
(fnorm/tree->db
 a
 union-tree
 true)

;;fails with:
;;[com.fulcrologic.fulcro.algorithms.normalize:135] -  Normalize failed and no data will be inserted into the client DB. Error: Union components must have an ident