Skip to content

Commit

Permalink
Merge pull request #217 from wilkerlucio/issue-216
Browse files Browse the repository at this point in the history
Fix wrong input order on nested resolvers
  • Loading branch information
wilkerlucio authored Aug 24, 2024
2 parents 4093b90 + 5791ad6 commit 91b5e66
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion src/main/com/wsscode/pathom3/connect/planner.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1584,6 +1590,9 @@
index-ast
(coll/filter-vals (comp seq :children) (pf.eql/index-ast placeholder-ast))))

(defn remove-parameterized-attributes [ast]
(eql/transduce-children (remove #(seq (:params %))) ast))

(defn compute-non-index-attribute
"This function deals with attributes that are not part of the index execution. The
cases here are:
Expand Down Expand Up @@ -1611,7 +1620,7 @@
(-> (add-placeholder-entry graph attr)
(cond->
(empty? (:params ast))
(-> (compute-run-graph* env)
(-> (compute-run-graph* (update env :edn-query-language.ast/node remove-parameterized-attributes))
(update ::index-ast merge-placeholder-ast ast))))))

(defn plan-mutation-nested-query [env {:keys [key] :as ast}]
Expand Down
2 changes: 1 addition & 1 deletion src/main/com/wsscode/pathom3/connect/runner.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@
(merge-entity-to-root-data env env' node)))
(do
(if (not= (count inputs) (count responses))
(throw (ex-info "Batch results must be a sequence and have the same length as the inputs." {:inputs inputs
(throw (ex-info "Batch results must be a sequence and have the same length as the inputs." {:inputs inputs
:op-name batch-op})))

(doseq [[{env' ::env
Expand Down
19 changes: 18 additions & 1 deletion test/com/wsscode/pathom3/connect/planner_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
51 changes: 26 additions & 25 deletions test/com/wsscode/pathom3/connect/runner_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2927,17 +2927,17 @@
:y 20}))))

(deftest run-graph!-placeholders-test
(is (graph-response? (pci/register (pbir/constantly-resolver :foo "bar"))
{}
[{:>/path [:foo]}]
{:foo "bar"
:>/path {:foo "bar"}}))
(check-all-runners
(pci/register (pbir/constantly-resolver :foo "bar"))
{}
[{:>/path [:foo]}]
{:>/path {:foo "bar"}})

(is (graph-response? (pci/register (pbir/constantly-resolver :foo "bar"))
{:foo "baz"}
[{:>/path [:foo]}]
{:foo "baz"
:>/path {:foo "baz"}}))
(check-all-runners (pci/register (pbir/constantly-resolver :foo "bar"))
{:foo "baz"}
[{:>/path [:foo]}]
{:foo "baz"
:>/path {:foo "baz"}})

(testing "keep split when placeholder uses different parameters"
(check-all-runners
Expand All @@ -2963,20 +2963,21 @@
{:>/a {:x "foo - 1"}, :>/b {:x "foo - 2"}}))

(testing "with batch"
(is (graph-response? (pci/register
[(pco/resolver 'batch
{::pco/batch? true
::pco/input [:x]
::pco/output [:y]}
(fn [_ xs]
(mapv #(array-map :y (inc (:x %))) xs)))])
{:x 10}
'[:y
{:>/go [:y]}]
{:x 10
:y 11
:>/go {:x 10
:y 11}})))
(check-all-runners
(pci/register
[(pco/resolver 'batch
{::pco/batch? true
::pco/input [:x]
::pco/output [:y]}
(fn [_ xs]
(mapv #(array-map :y (inc (:x %))) xs)))])
{:x 10}
'[:y
{:>/go [:y]}]
{:x 10
:y 11
:>/go {:x 10
:y 11}}))

(testing "placeholder-data-params"
(check-all-runners
Expand Down Expand Up @@ -3021,7 +3022,7 @@
{:>/m3 [(:y {:m 3})]}
{:>/m4 [(:y {:m 4})]}]
{:x 10
:y 30
:y 20
:>/m2 {:x 10
:y 20}
:>/m3 {:x 10
Expand Down

0 comments on commit 91b5e66

Please sign in to comment.