From 8960b70d939d73164015996b7887936346e444fd Mon Sep 17 00:00:00 2001 From: Wilker Lucio Date: Sat, 24 Aug 2024 02:55:27 -0300 Subject: [PATCH] Ensure all instances of same resolver in same graph have same params --- CHANGELOG.md | 1 + .../com/wsscode/pathom3/connect/planner.cljc | 21 +++++++- .../wsscode/pathom3/connect/planner_test.cljc | 54 ++++++++++++++++++- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5727323c..b3cb82dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Fix `pf.eql/map-select` case on map container at query - Fix spec for `pco/?` - Merge params when merging nodes on planner (issue #216) +- Ensure all instances of same resolver in same graph have same params (issue #211) ## [2023.08.22-alpha] - BREAKING: `::p.error/missing-output` is now converged to `::p.error/attribute-missing` (issue #149) diff --git a/src/main/com/wsscode/pathom3/connect/planner.cljc b/src/main/com/wsscode/pathom3/connect/planner.cljc index 50fde443..bd5db9e9 100644 --- a/src/main/com/wsscode/pathom3/connect/planner.cljc +++ b/src/main/com/wsscode/pathom3/connect/planner.cljc @@ -1768,6 +1768,22 @@ (assoc ::placeholder-use-source-entity? true))) index-ast)))) +(defn ensure-resolver-consistent-params [graph] + (reduce + (fn [graph' node-ids] + (if (> (count node-ids) 1) + (let [params (transduce (map #(get-node graph' % ::params)) merge node-ids)] + (if (seq params) + (reduce + (fn [graph'' node-id] + (assoc-node graph'' node-id ::params params)) + graph' + node-ids) + graph')) + graph')) + graph + (vals (::index-resolver->nodes graph)))) + (>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 @@ -1853,7 +1869,10 @@ (optimize-graph env') true - (mark-fast-placeholder-processes env')))) + (mark-fast-placeholder-processes env') + + true + (ensure-resolver-consistent-params)))) (:edn-query-language.ast/node env))))) ; endregion diff --git a/test/com/wsscode/pathom3/connect/planner_test.cljc b/test/com/wsscode/pathom3/connect/planner_test.cljc index 337e4fda..966f595e 100644 --- a/test/com/wsscode/pathom3/connect/planner_test.cljc +++ b/test/com/wsscode/pathom3/connect/planner_test.cljc @@ -1610,7 +1610,59 @@ :com.wsscode.pathom3.connect.planner/user-request-shape {:a {}, :b {}}, :com.wsscode.pathom3.connect.planner/index-resolver->nodes {a #{1}}, :com.wsscode.pathom3.connect.planner/index-attrs {:a #{1}, :b #{1}}, - :com.wsscode.pathom3.connect.planner/root 1})))) + :com.wsscode.pathom3.connect.planner/root 1}))) + + (testing "all resolver calls from same resolver must have consistent parameters" + (check (=> '{:com.wsscode.pathom3.connect.planner/nodes {1 {:com.wsscode.pathom3.connect.operation/op-name email-body, + :com.wsscode.pathom3.connect.planner/expects {:email/body {}}, + :com.wsscode.pathom3.connect.planner/input {}, + :com.wsscode.pathom3.connect.planner/node-id 1, + :com.wsscode.pathom3.connect.planner/params {:text? true}, + :com.wsscode.pathom3.connect.planner/node-parents #{6}}, + 2 {:com.wsscode.pathom3.connect.operation/op-name email-valid?, + :com.wsscode.pathom3.connect.planner/expects {:email/valid? {}}, + :com.wsscode.pathom3.connect.planner/input {:email/body {}, + :email/subject {}}, + :com.wsscode.pathom3.connect.planner/node-id 2, + :com.wsscode.pathom3.connect.planner/node-parents #{5}}, + 3 {:com.wsscode.pathom3.connect.operation/op-name email-body, + :com.wsscode.pathom3.connect.planner/expects {:email/body {}}, + :com.wsscode.pathom3.connect.planner/input {}, + :com.wsscode.pathom3.connect.planner/node-id 3, + :com.wsscode.pathom3.connect.planner/params {:text? true}, + :com.wsscode.pathom3.connect.planner/node-parents #{5}}, + 4 {:com.wsscode.pathom3.connect.operation/op-name email-subject, + :com.wsscode.pathom3.connect.planner/expects {:email/subject {}}, + :com.wsscode.pathom3.connect.planner/input {}, + :com.wsscode.pathom3.connect.planner/node-id 4, + :com.wsscode.pathom3.connect.planner/node-parents #{5}}, + 5 {:com.wsscode.pathom3.connect.planner/node-id 5, + :com.wsscode.pathom3.connect.planner/run-and #{4 3}, + :com.wsscode.pathom3.connect.planner/run-next 2, + :com.wsscode.pathom3.connect.planner/node-parents #{6}}, + 6 {:com.wsscode.pathom3.connect.planner/node-id 6, + :com.wsscode.pathom3.connect.planner/run-and #{1 5}}}, + :com.wsscode.pathom3.connect.planner/index-ast {:email/body {:type :prop, + :dispatch-key :email/body, + :key :email/body, + :params {:text? true}}, + :email/valid? {:type :prop, + :dispatch-key :email/valid?, + :key :email/valid?}}, + :com.wsscode.pathom3.connect.planner/user-request-shape {:email/body {}, :email/valid? {}}, + :com.wsscode.pathom3.connect.planner/index-resolver->nodes {email-body #{1 3}, email-valid? #{2}, email-subject #{4}}, + :com.wsscode.pathom3.connect.planner/index-attrs {:email/body #{1 3}, :email/valid? #{2}, :email/subject #{4}}, + :com.wsscode.pathom3.connect.planner/root 6} + (compute-run-graph + {::pci/index-oir '{:email/body + {{} #{email-body}}, + :email/subject + {{} #{email-subject}}, + :email/valid? + {{:email/body {}, :email/subject {}} + #{email-valid?}}} + ::eql/query ['(:email/body {:text? true}) + :email/valid?]}))))) (deftest compute-run-graph-optimize-test (testing "optimize AND nodes"