Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: investigate bug with nested inputs #223

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 44 additions & 31 deletions src/main/com/wsscode/pathom3/connect/planner.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@
attribute"
[{:com.wsscode.pathom3.error/keys [lenient-mode?]
:as env} graph]
(if lenient-mode?
(if true #_lenient-mode?
(try
(verify-plan!* env graph)
(catch #?(:clj Throwable :cljs :default) _
Expand Down Expand Up @@ -1781,6 +1781,8 @@
graph
(vals (::index-resolver->nodes graph))))

(defonce compute-run-graph-state-atom (atom 0))

(>defn compute-run-graph
"Generates a run plan for a given environment, the environment should contain the
indexes in it (::pc/index-oir and ::pc/index-resolvers). It computes a plan to execute
Expand Down Expand Up @@ -1843,36 +1845,47 @@
(add-snapshot! graph env {::snapshot-event ::snapshot-start-graph
::snapshot-message "=== Start query plan ==="})

(p.plugin/run-with-plugins env ::wrap-compute-run-graph
(fn compute-run-graph-internal [graph env]
(as-> env <>
(p.cache/cached ::plan-cache* <> [(hash (::pci/index-oir env))
(::available-data env)
(pf.eql/cacheable-ast (:edn-query-language.ast/node env))
(boolean optimize-graph?)]
#(let [env' (-> (merge (base-env) env)
(vary-meta assoc ::original-env env))]
(cond->
(compute-run-graph*
(merge (base-graph)
graph
{::index-ast (pf.eql/index-ast (:edn-query-language.ast/node env))
::source-ast (:edn-query-language.ast/node env)
::available-data (::available-data env)
::user-request-shape (pfsd/ast->shape-descriptor (:edn-query-language.ast/node env))})
env')

optimize-graph?
(optimize-graph env')

true
(mark-fast-placeholder-processes env')

true
(ensure-resolver-consistent-params))))
(rehydrate-graph-idents <> (:edn-query-language.ast/node env))
(verify-plan! env <>)))
graph env)))
(swap! compute-run-graph-state-atom inc)
(let [g2 (p.plugin/run-with-plugins env ::wrap-compute-run-graph
(fn compute-run-graph-internal [graph env]
(as-> env <>
(p.cache/cached ::plan-cache* <> [(hash (::pci/index-oir env))
(::available-data env)
(pf.eql/cacheable-ast (:edn-query-language.ast/node env))
(boolean optimize-graph?)]
#(let [env' (-> (merge (base-env) env)
(vary-meta assoc ::original-env env))]
(cond->
(compute-run-graph*
(merge (base-graph)
graph
{::index-ast (pf.eql/index-ast (:edn-query-language.ast/node env))
::source-ast (:edn-query-language.ast/node env)
::available-data (::available-data env)
::user-request-shape (pfsd/ast->shape-descriptor (:edn-query-language.ast/node env))})
env')

optimize-graph?
(optimize-graph env')

true
(mark-fast-placeholder-processes env')

true
(ensure-resolver-consistent-params))))
(rehydrate-graph-idents <> (:edn-query-language.ast/node env))
(verify-plan! env <>)))
graph env)]

(let []
(if (= 0 (swap! compute-run-graph-state-atom dec))
(if (:com.wsscode.pathom3.error/lenient-mode? env)
(try
(verify-plan!* env g2)
(catch #?(:clj Throwable :cljs :default) _
(assoc g2 ::verification-failed? true)))
(verify-plan!* env g2))
g2)))))

; endregion

Expand Down
26 changes: 26 additions & 0 deletions test/com/wsscode/pathom3/connect/planner_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4636,3 +4636,29 @@
{::resolvers [{::pco/op-name 'x
::pco/output [:x]}]
::eql/query [{:>/a ['(:x {:foo 1})]}]}))))

(deftest missing-but-uneccessary-nested-inputs
(let [env (-> (pci/register
[(pco/resolver
{::pco/op-name 'temp-from-sensors
::pco/input [{:room/sensors [:sensor/high :sensor/low]}]
::pco/output [::temperature]
::pco/resolve (fn [_ input]
(let [{:sensor/keys [high low]} (get input :room/sensors)]
{::temperature (/ (+ high low) 2)}))})

(pco/resolver
{::pco/op-name 'temp-from-direct
::pco/priority 100 ;;adding priority doesn't help
::pco/input [:room/temperature]
::pco/output [::temperature]
::pco/resolve (fn [_ input]
{::temperature (:room/temperature input)})})]))]


(is (= {}
(p.eql/process env
{
:room/temperature 72
:room/sensors {}}
[::temperature])))))
Loading