Skip to content

Commit

Permalink
Support AND nodes on branch error details
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkerlucio committed Dec 10, 2024
1 parent c10ad88 commit c14aee7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
10 changes: 5 additions & 5 deletions src/main/com/wsscode/pathom3/connect/runner.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,9 @@
(node-missing-input-error-details env node attr)
(input-missing-error-message-leaf [node] attr)))

(defn input-missing-detail-OR
[{::pcp/keys [graph]} or-node attr]
(let [resolver-nodes (->> (pcp/node-successors graph (::pcp/node-id or-node))
(defn input-missing-detail-branch-node
[{::pcp/keys [graph]} branch-node attr]
(let [resolver-nodes (->> (pcp/node-successors graph (::pcp/node-id branch-node))
(map #(pcp/get-node graph %))
(filter #(and
(contains? (::pcp/expects %) attr)
Expand All @@ -507,8 +507,8 @@
(map #(pcp/get-node graph %))
(filter #(contains? (::pcp/expects %) attr))
first)]
(if (::pcp/run-or missed-parent-node)
(input-missing-detail-OR env missed-parent-node attr)
(if (pcp/branch-node? missed-parent-node)
(input-missing-detail-branch-node env missed-parent-node attr)
(input-missing-error-message env missed-parent-node attr))
(str "Can't find parent node that should provide attribute " attr ", this is likely a bug in Pathom, please report it.")))

Expand Down
47 changes: 23 additions & 24 deletions test/com/wsscode/pathom3/connect/runner_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -966,32 +966,31 @@
:ex/data {::pcr/attributes-missing {:c {}}}}))

(testing "missed attribute comes from AND node"
(comment
(check-all-runners-ex
(pci/register
[(pco/resolver 'a
{::pco/output [:a]}
(fn [_ _]
{}))
(check-all-runners-ex
(pci/register
[(pco/resolver 'a
{::pco/output [:a]}
(fn [_ _]
{}))

(pco/resolver 'b
{::pco/output [:b]}
(fn [_ _]
{}))
(pco/resolver 'b
{::pco/output [:b]}
(fn [_ _]
{}))

(pco/resolver 'c
{::pco/input [:a :b]
::pco/output [:c]}
(fn [_ _]
{}))])
{}
[:c]
{:ex/message (str
"Required attributes missing:\n"
"- Attribute :c was expected to be returned from resolver c but inputs were missing:\n"
" - Attribute :a was expected to be returned from resolver a but it failed to provide it.\n"
" - Attribute :b was expected to be returned from resolver b but it failed to provide it.")
:ex/data {::pcr/attributes-missing {:c {}}}})))))
(pco/resolver 'c
{::pco/input [:a :b]
::pco/output [:c]}
(fn [_ _]
{}))])
{}
[:c]
{:ex/message (str
"Required attributes missing:\n"
"- Attribute :c was expected to be returned from resolver c but inputs were missing:\n"
" - Attribute :a was expected to be returned from resolver a but it failed to provide it.\n"
" - Attribute :b was expected to be returned from resolver b but it failed to provide it.")
:ex/data {::pcr/attributes-missing {:c {}}}}))))

(deftest run-graph!-final-test
(testing "map value"
Expand Down

0 comments on commit c14aee7

Please sign in to comment.