Skip to content

Commit

Permalink
Starting test to design errors for missing deps at planner
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkerlucio committed Dec 7, 2024
1 parent 3031351 commit 470f21c
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 58 deletions.
17 changes: 8 additions & 9 deletions src/main/com/wsscode/pathom3/connect/planner.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1692,15 +1692,14 @@
(update source-ast :children
#(into (with-meta [] (meta %)) keep-required-transducer %)))

(defn unreachable-details [{::pci/keys [index-oir]} graph missing]
(into {}
(map (fn [[k]]
(let [cause (if (contains? index-oir k)
{::unreachable-cause ::unreachable-cause-missing-inputs
::unreachable-missing-inputs {}}
{::unreachable-cause ::unreachable-cause-unknown-attribute})]
[k cause])))
missing))
(defn unreachable-attr-cause [{::pci/keys [index-oir]} _graph attr]
(if (contains? index-oir attr)
{::unreachable-cause ::unreachable-cause-missing-inputs
::unreachable-missing-inputs {}}
{::unreachable-cause ::unreachable-cause-unknown-attribute}))

(defn unreachable-details [env graph missing]
(into {} (map (fn [[k]] [k (unreachable-attr-cause env graph k)])) missing))

(defn unreachable-detail-string [_env attr cause]
(case (::unreachable-cause cause)
Expand Down
165 changes: 116 additions & 49 deletions test/com/wsscode/pathom3/connect/planner_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,14 @@
{::resolvers []
::eql/query [:a :b]})))

;; WIP - figuring out the format, will comment for now so CI passes
#_
(testing "broken chain"
(check (=> {:ex/message
(str
"Pathom can't find a path for the following elements in the query:\n"
"- Attribute :b dependencies can't be met, details: WIP")
"- Attribute :b inputs can't be met, details:\n"
" - Missing attribute :a")

:ex/data
{::pcp/unreachable-paths {:b {}}
Expand All @@ -300,54 +303,118 @@
::pco/output [:b]}]
::eql/query [:b]})))

(check (=> {:ex/message
(str
"Pathom can't find a path for the following elements in the query:\n"
"- Attribute :b dependencies can't be met, details: WIP")}
(compute-run-graph-ex
{::pci/index-oir '{:b {{:a {}} #{b1 b}}}
::eql/query [:b]})))

(check (=> {:ex/message
(str
"Pathom can't find a path for the following elements in the query:\n"
"- Attribute :b dependencies can't be met, details: WIP")}
(compute-run-graph-ex
{::resolvers [{::pco/op-name 'a
::pco/output [:a]}
{::pco/op-name 'b
::pco/input [:a]
::pco/output [:b]}]
::eql/query [:b]
::out {::pcp/unreachable-paths {:a {}}}})))

(check (=> {:ex/message
(str
"Pathom can't find a path for the following elements in the query:\n"
"- Attribute :c dependencies can't be met, details: WIP")}
(compute-run-graph-ex
{::resolvers [{::pco/op-name 'b
::pco/input [:a]
::pco/output [:b]}
{::pco/op-name 'c
::pco/input [:b]
::pco/output [:c]}]
::eql/query [:c]})))

(check (=> {:ex/message
(str
"Pathom can't find a path for the following elements in the query:\n"
"- Attribute :c dependencies can't be met, details: WIP")}
(compute-run-graph-ex
{::resolvers [{::pco/op-name 'b
::pco/input [:a]
::pco/output [:b]}
{::pco/op-name 'd
::pco/output [:d]}
{::pco/op-name 'c
::pco/input [:b :d]
::pco/output [:c]}]
::eql/query [:c]}))))
(testing "partial failure"
(check (=> {:ex/message
(str
"Pathom can't find a path for the following elements in the query:\n"
"- Attribute :b inputs can't be met, details:\n"
" - Missing attribute :a")}
(compute-run-graph-ex
{::resolvers [{::pco/op-name 'b
::pco/input [:a :c]
::pco/output [:b]}
{::pco/op-name 'c
::pco/output [:c]}]
::eql/query [:b]})))

(check (=> {:ex/message
(str
"Pathom can't find a path for the following elements in the query:\n"
"- Attribute :b inputs can't be met, details:\n"
" - Missing attribute :a")}
(compute-run-graph-ex
{::resolvers [{::pco/op-name 'b
::pco/input [:a :c]
::pco/output [:b]}]
::pcp/available-data {:c {}}
::eql/query [:b]}))))

(testing "with multiple paths using same input"
(check (=> {:ex/message
(str
"Pathom can't find a path for the following elements in the query:\n"
"- Attribute :b inputs can't be met, details:\n"
" - Missing attribute :a")}
(compute-run-graph-ex
{::resolvers [{::pco/op-name 'b
::pco/input [:a]
::pco/output [:b]}
{::pco/op-name 'b1
::pco/input [:a]
::pco/output [:b]}]
::eql/query [:b]}))))

(testing "missing with indirect chain"
(check (=> {:ex/message
(str
"Pathom can't find a path for the following elements in the query:\n"
"- Attribute :c inputs can't be met, details:\n"
" - Missing attribute :b\n"
" - Provide :a to use path: :a -> :b")}
(compute-run-graph-ex
{::resolvers [{::pco/op-name 'b
::pco/input [:a]
::pco/output [:b]}
{::pco/op-name 'c
::pco/input [:b]
::pco/output [:c]}]
::eql/query [:c]})))

(check (=> {:ex/message
(str
"Pathom can't find a path for the following elements in the query:\n"
"- Attribute :d inputs can't be met, details:\n"
" - Missing attribute :c\n"
" - Provide :b to use path: :b -> :c\n"
" - Provide :a to use path: :a -> :b -> :c")}
(compute-run-graph-ex
{::resolvers [{::pco/op-name 'b
::pco/input [:a]
::pco/output [:b]}
{::pco/op-name 'c
::pco/input [:b]
::pco/output [:c]}
{::pco/op-name 'd
::pco/input [:c]
::pco/output [:d]}]
::eql/query [:d]}))))

(testing "multiple missing with inputs of different complexity"
(check (=> {:ex/message
(str
"Pathom can't find a path for the following elements in the query:\n"
"- Attribute :c inputs can't be met, details:\n"
" - Missing attribute :b\n"
" - Provide :a to use path: :a -> :b\n"
" - Missing attribute :d")}
(compute-run-graph-ex
{::resolvers [{::pco/op-name 'b
::pco/input [:a]
::pco/output [:b]}
{::pco/op-name 'd
::pco/output [:d]}
{::pco/op-name 'c
::pco/input [:b :d]
::pco/output [:c]}]
::eql/query [:c]}))))

(testing "multiple attributes missing that can come from same parent missing input"
(check (=> {:ex/message
(str
"Pathom can't find a path for the following elements in the query:\n"
"- Attribute :d dependencies can't be met, details:\n"
" - Missing attribute :b\n"
" - Provide :a to use path: :a -> :b\n"
" - Missing attribute :c\n"
" - Provide :a to use path: :a -> :c")}
(compute-run-graph-ex
{::resolvers [{::pco/op-name 'a->bc
::pco/input [:a]
::pco/output [:b :c]}
{::pco/op-name 'd
::pco/input [:b :c]
::pco/output [:d]}]
::eql/query [:d]})))))

(testing "currently available data"
(is (= (compute-run-graph
Expand Down

0 comments on commit 470f21c

Please sign in to comment.