Skip to content

Commit f766b07

Browse files
committed
Fix cypher nested subqueries not using the same parameter bag
This affected `where` clauses which added parameters at `build()`
1 parent 27aa955 commit f766b07

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/core/database/query-augmentation/SubClauseCollection.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1-
import { ClauseCollection, Query } from 'cypher-query-builder';
1+
import { Clause, ClauseCollection, Query } from 'cypher-query-builder';
2+
import type { ParameterBag } from 'cypher-query-builder/dist/typings/parameter-bag';
23

34
export class SubClauseCollection extends ClauseCollection {
5+
useParameterBag(newBag: ParameterBag) {
6+
super.useParameterBag(newBag);
7+
this.assignBagRecursive(this, newBag);
8+
}
9+
10+
private assignBagRecursive(clause: Clause, newBag: ParameterBag) {
11+
// @ts-expect-error protected, but we want it to reference the outer one
12+
// without having to import the parameters.
13+
clause.parameterBag = newBag;
14+
if (clause instanceof ClauseCollection) {
15+
for (const sub of clause.getClauses()) {
16+
this.assignBagRecursive(sub, newBag);
17+
}
18+
}
19+
}
20+
421
build() {
522
return this.clauses
623
.flatMap((clause) => {

0 commit comments

Comments
 (0)