Skip to content

Commit

Permalink
Ensure all instances of same resolver in same graph have same params
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkerlucio committed Aug 24, 2024
1 parent 91b5e66 commit 8960b70
Show file tree
Hide file tree
Showing 3 changed files with 74 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
21 changes: 20 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,22 @@
(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
(fn [graph'' node-id]
(assoc-node graph'' node-id ::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 +1869,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 8960b70

Please sign in to comment.