diff --git a/CHANGELOG.md b/CHANGELOG.md index 42bb6738..5727323c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fix wrong input order on nested resolvers (issue #205) - Fix `pf.eql/map-select` case on map container at query - Fix spec for `pco/?` +- Merge params when merging nodes on planner (issue #216) ## [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 fddfc4fd..cc8942fb 100644 --- a/src/main/com/wsscode/pathom3/connect/planner.cljc +++ b/src/main/com/wsscode/pathom3/connect/planner.cljc @@ -702,6 +702,11 @@ (defn combine-expects [na nb] (update na ::expects pfsd/merge-shapes (::expects nb))) +(defn combine-params [na nb] + (cond-> na + (or (::params na) (::params nb)) + (update ::params merge (::params nb)))) + (defn combine-inputs [na nb] (if (::input nb) (update na ::input pfsd/merge-shapes (::input nb)) @@ -809,6 +814,7 @@ (-> graph ; merge any extra keys from source node, but without overriding anything (update-node target-node-id nil coll/merge-defaults source-node) + (update-node target-node-id nil combine-params source-node) (update-node target-node-id nil combine-expects source-node) (update-node target-node-id nil combine-inputs source-node) (update-node target-node-id nil combine-foreign-ast source-node) diff --git a/test/com/wsscode/pathom3/connect/planner_test.cljc b/test/com/wsscode/pathom3/connect/planner_test.cljc index 59bd8abe..337e4fda 100644 --- a/test/com/wsscode/pathom3/connect/planner_test.cljc +++ b/test/com/wsscode/pathom3/connect/planner_test.cljc @@ -1593,7 +1593,24 @@ ::pcp/input {} ::pcp/node-id 1 ::pcp/params {:x 1}}} - ::pcp/root 1}))))) + ::pcp/root 1})))) + + (testing "params should merge when different attributes are related to same node call" + (is (= (compute-run-graph + {::resolvers [{::pco/op-name 'a + ::pco/output [:a :b]}] + ::eql/query [(list :a {:x "y"}) (list :b {:z "foo"})]}) + '{:com.wsscode.pathom3.connect.planner/nodes {1 {:com.wsscode.pathom3.connect.operation/op-name a, + :com.wsscode.pathom3.connect.planner/expects {:a {}, :b {}}, + :com.wsscode.pathom3.connect.planner/input {}, + :com.wsscode.pathom3.connect.planner/node-id 1, + :com.wsscode.pathom3.connect.planner/params {:x "y", :z "foo"}}}, + :com.wsscode.pathom3.connect.planner/index-ast {:a {:type :prop, :dispatch-key :a, :key :a, :params {:x "y"}}, + :b {:type :prop, :dispatch-key :b, :key :b, :params {:z "foo"}}}, + :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})))) (deftest compute-run-graph-optimize-test (testing "optimize AND nodes"