Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure all instances of same resolver in same graph have same params #218

Merged
merged 2 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading