wilkerlucio / pathom3

Interface with complex data via graph mapping.
https://pathom3.wsscode.com
Eclipse Public License 2.0
374 stars 31 forks source link

Implicit resolver priority based on number of input attributes #202

Closed MrEbbinghaus closed 1 month ago

MrEbbinghaus commented 1 year ago

(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.)

yenda commented 10 months ago

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,