pathom

Schmoho 2025-03-29T14:18:57.124239Z

Hi! I am playing around with Pathom for the first time and came across a scenario where I wonder what the "best practice" approach is. The data I am working with comes from lots of different databases and on each database, entries tend to have lists of references like this:

[#database.xref{:database "some-database-ref",
                :id "some-database-id"}
 ,,,]
Which databases occur in a list like this varies, and the same database might occur multiple times with different IDs. Given an external ID, it is trivial to write a resolver to get the record. So I figured what I probably want are "typed" resolvers that only give the filtered lists for a specific database, s.t. I can then call the contained ID some-db/id instead of database.xref/id? From what I gather from the Pathom3 docs I'll likely want to either dynamically create resolvers for this or use a query parameter to filter the list and dynamically re-namespace the ID? What is the best practice approach to this?

Schmoho 2025-03-29T14:59:24.006489Z

I ended up doing this:

(defn xref-db-resolver [db-name]
  (let [symbol-db-name (str/lower-case db-name)]
    (pco/resolver
     {::pco/op-name (symbol (str *ns*) (str "database-" symbol-db-name "-references"))
      ::pco/input   [:database.entry/database-cross-references]
      ::pco/output  [(keyword "database.entry" (str symbol-db-name "-xrefs"))]
      ::pco/resolve (fn [env input]
                      {(keyword "database.entry" (str symbol-db-name "-xrefs"))
                       (keep
                        (fn [xref]
                          (prn xref)
                          (when (= db-name (:database.entry.xref/database xref))
                            {(keyword symbol-db-name "id") (:database.entry.xref/id xref)}))
                        (:database.entry/database-cross-references input))})})))