This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-31
Channels
- # aws (18)
- # babashka (35)
- # beginners (7)
- # cider (3)
- # clara (2)
- # clj-kondo (15)
- # cljs-dev (1)
- # cljsrn (3)
- # clojure (20)
- # clojure-canada (1)
- # clojure-dev (3)
- # clojure-spec (17)
- # clojure-uk (13)
- # clojutre (1)
- # cursive (7)
- # datomic (1)
- # duct (7)
- # fulcro (33)
- # helix (77)
- # jobs (3)
- # malli (15)
- # meander (3)
- # off-topic (30)
- # pathom (3)
- # quil (1)
- # reagent (1)
- # reitit (10)
- # shadow-cljs (2)
- # tools-deps (5)
- # xtdb (6)
- # yada (1)
I'm trying to get a union resolver/query to work but have failed so far. I have made a simple example with my best attempt so far, and I would be really happy if someone could point out what I'm doing wrong 🙂 Is it correct that union resolvers are specified just as a normal output join, and the union "logic" is present just in the query? I'm on pathom version 2.2.30.
I think I've figured out what I'm doing wrong now, union resolvers can't be "to-many" (or can they?).
By introducing the concept of a single "search-result", the resolver now looks like:
(pc/defresolver search-resolver
[_ {:keys [search/term]}]
{::pc/input #{:search/term}
::pc/output [{:search/results
[{:search/result [:image/id :video/id]}]}]}
{:search/results [{:search/result {:image/id 1}}
{:search/result {:video/id 3}}]})
The query:
(async/<!! (parser {} [{[:search/term "my-search-term"]
[{:search/results
[{:search/result
{:image/id [:image/name]
:video/id [:video/title]}}]}]}]))
;; => {[:search/term "my-search-term"] #:search{:results [#:search{:result #:image{:name "Red flower"}}
;; #:search{:result #:video{:title "A day in life"}}]}}
Success!