pathom3
pathom3 copied to clipboard
Implicit resolver priority based on number of input attributes
(See Slack Discussion for further reference)
Resolvers with higher specificity should get priority over resolvers with less specificity. Specificity can be determined by the number of input attributes.
Problem Statement
Given following resolvers
(defresolver resolve-full-name-by-first-name [{:keys [first-name]}]
{:person/full-name first-name})
(defresolver resolve-full-name-with-first-and-last-name [{:keys [first-name last-name]}]
{:person/full-name (str first-name " " last-name)})
and this query
[([:person/full-name] {:person/first-name "Björn", :person/last-name "Ebbinghaus"})]
Currently, the output could be:
[{:person/full-name "Björn"}]
; or
[{:person/full-name "Björn Ebbinghaus"}]
Since both resolvers could provide :person/full-name given the input.
Possible Solution
Prioritise resolvers with higher specificity. This would make pathoms behaviour predictable:
; always
[{:person/full-name "Björn Ebbinghaus"}]
(This would be a non-breaking change, except if someone depends on the random behaviour.)
pathom3 has pco/? to make an input optional, so in your example last-name should just be an optional input and there should only be one resolver for full-name,