Fork me on GitHub

Hello 👋

👋 21

New docs section on using Recursive queries with EQL on Pathom 3:

parrot 6
👏 12
clojure-spin 3
😍 3

Have you given any thought to multimethod-like dispatch for resolvers? For example, I might have a compute-cost resolver that dispatches based on an input parameter product/type to resolvers compute-book-cost and compute-fish-cost that have different inputs. I can see how I might use optional inputs to achieve the desired result but that approach seems a little messy.


not sure if I understand the issue, you can already have multiple options for the same value (multiple resolvers with same output, different input), with different dependencies. can you make an example?


I have a use case of two resolvers taking different inputs and producing the same output.


When the inputs for resolver A are satisfied, I'd like Pathom to execute that resolver. When the inputs for resolver B are satisfied, obviously execute the other.


I can see a way to implement this in Pathom 3 using optional inputs but it seems a little messy.


you don't need optional input, just make 2 resolvers with the same output, the exact thing you described is what pathom does


code in Pathom 3 (but works the same in Pathom 2):


(pco/defresolver c-from-a [{:keys [a]}]
  {:c (str a "A")})

(pco/defresolver c-from-b [{:keys [b]}]
  {:c (str b "B")})

(def paths-env (pci/register [c-from-a c-from-b]))

(p.eql/process paths-env {:a 1} [:c])
=> {:c "1A"}
(p.eql/process paths-env {:b 2} [:c])
=> {:c "2B"}