pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
2020-05-31T16:01:01.162Z

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.

2020-06-01T08:25:05.168600Z

I think I've figured out what I'm doing wrong now, union resolvers can't be "to-many" (or can they?).

2020-06-01T08:32:16.168800Z

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!