Fork me on GitHub
#pathom
<
2023-03-30
>
timovanderkamp12:03:41

I am using a foreign registry and im running into, what I believe to be, an issue with a union query. The union query looks something like this:

[:event/id
 {:event/properties {:event.x/id [:event.y/id :event.x/name]
                     :event.y/id [:event.y/id :event.y/name]}}]
However, when the foreign registry tries to resolve the query, it is turned into this:
[:event/id
 {:event/properties [:event.x/id :event.x/name :event.y/id :.event.y/name]}]
(pci/register [(pcf/foreign-register
                (fn [query]
                  (println :query query)
                  (if (= query [:com.wsscode.pathom3.connect.indexes/indexes])
                    (get-parser-indexes)
                    (query-from-foreign-api! query))))])
Is this expected behaviour?

wilkerlucio21:03:28

to be honest I can't remember what happens in this case, since this is very untested group my initial feeling is its a bug, but need some case to verify, can you make a repro please?

timovanderkamp09:03:28

(ns parser-bug-reproduction
  (:require
   [com.wsscode.pathom3.connect.foreign :as pcf]
   [com.wsscode.pathom3.connect.planner :as pcp]
   [com.wsscode.pathom3.connect.indexes :as pci]
   [com.wsscode.pathom3.connect.operation :as pco]
   [com.wsscode.pathom3.interface.async.eql :as p.a.eql]))

(pco/defresolver event-log [env _]
  {::pco/output [{:events [:event/id
                           {:event/properties {:event.x/id [:event.x/id :event.x/name]
                                               :event.y/id [:event.y/id :event.y/name]}}]}]}
  {:events [{:event/id "x"
             :event/properties {:event.x/id "x" :event.x/name "event x"}}
            {:event/id "y"
             :event/properties {:event.y/id "x" :event.y/name "event x"}}]})

(def foreign-indexes
  (->
   {::p.a.eql/parallel? true}
   (pci/register [event-log])
   (pcp/with-plan-cache)))

(def foreign-parse* (p.a.eql/boundary-interface foreign-indexes))

(defn foreign-parse! [env ast] (foreign-parse* env ast))

(defn get-foreign-indexes [env]
  @(foreign-parse! env [:com.wsscode.pathom3.connect.indexes/indexes]))

(def indexes
  (-> {::p.a.eql/parallel? true}
      (pci/register [(pcf/foreign-register
                      (fn [query]
                        (println :query query)
                        (if (= query [:com.wsscode.pathom3.connect.indexes/indexes])
                          (get-foreign-indexes {})
                          (foreign-parse! {} query))))])
      (pcp/with-plan-cache)))

(def parse! (p.a.eql/boundary-interface indexes))


(comment

  @(parse! {} [{:events [:event/id
                        {:event/properties {:event.x/id [:event.x/id :event.x/name]
                                            :event.y/id [:event.y/id :event.y/name]}}]}])

  )

timovanderkamp09:03:34

Here you go 🙂

🙏 2