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..503ff4d6 100644 --- a/src/main/com/wsscode/pathom3/connect/planner.cljc +++ b/src/main/com/wsscode/pathom3/connect/planner.cljc @@ -1768,6 +1768,18 @@ (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 #(assoc-node % %2 ::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 +1865,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"