Skip to content

Commit

Permalink
Merge pull request #218 from wilkerlucio/issue-211
Browse files Browse the repository at this point in the history
Ensure all instances of same resolver in same graph have same params
  • Loading branch information
wilkerlucio authored Aug 24, 2024
2 parents 91b5e66 + 3f5451a commit 46b3b0a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 16 additions & 1 deletion src/main/com/wsscode/pathom3/connect/planner.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
54 changes: 53 additions & 1 deletion test/com/wsscode/pathom3/connect/planner_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 46b3b0a

Please sign in to comment.