Skip to content

Commit d2a7c5e

Browse files
Lenz Weberjuliendangers
authored andcommitted
correctly wrap joined where clauses and conditions in parenthesis
1 parent 06180a8 commit d2a7c5e

4 files changed

+16
-16
lines changed

src/PostgraphileNestedConnectorsPlugin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module.exports = function PostGraphileNestedConnectorsPlugin(builder) {
7777
if (identifiers.length !== primaryKeys.length) {
7878
throw new Error('Invalid ID');
7979
}
80-
where = sql.fragment`${sql.join(
80+
where = sql.fragment`(${sql.join(
8181
primaryKeys.map(
8282
(key, idx) =>
8383
sql.fragment`${sql.identifier(key.name)} = ${gql2pg(
@@ -87,10 +87,10 @@ module.exports = function PostGraphileNestedConnectorsPlugin(builder) {
8787
)}`,
8888
),
8989
') and (',
90-
)}`;
90+
)})`;
9191
} else {
9292
const foreignPrimaryKeys = constraint.keyAttributes;
93-
where = sql.fragment`${sql.join(
93+
where = sql.fragment`(${sql.join(
9494
foreignPrimaryKeys.map(
9595
(k) => sql.fragment`
9696
${sql.identifier(k.name)} = ${gql2pg(
@@ -101,7 +101,7 @@ module.exports = function PostGraphileNestedConnectorsPlugin(builder) {
101101
`,
102102
),
103103
') and (',
104-
)}`;
104+
)})`;
105105
}
106106
const select = foreignKeys.map((k) => sql.identifier(k.name));
107107
const query = parentRow

src/PostgraphileNestedDeletersPlugin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module.exports = function PostGraphileNestedDeletersPlugin(builder) {
7777
if (identifiers.length !== primaryKeys.length) {
7878
throw new Error('Invalid ID');
7979
}
80-
where = sql.fragment`${sql.join(
80+
where = sql.fragment`(${sql.join(
8181
primaryKeys.map(
8282
(key, idx) =>
8383
sql.fragment`${sql.identifier(key.name)} = ${gql2pg(
@@ -87,10 +87,10 @@ module.exports = function PostGraphileNestedDeletersPlugin(builder) {
8787
)}`,
8888
),
8989
') and (',
90-
)}`;
90+
)})`;
9191
} else {
9292
const foreignPrimaryKeys = constraint.keyAttributes;
93-
where = sql.fragment`${sql.join(
93+
where = sql.fragment`(${sql.join(
9494
foreignPrimaryKeys.map(
9595
(k) => sql.fragment`
9696
${sql.identifier(k.name)} = ${gql2pg(
@@ -101,7 +101,7 @@ module.exports = function PostGraphileNestedDeletersPlugin(builder) {
101101
`,
102102
),
103103
') and (',
104-
)}`;
104+
)})`;
105105
}
106106
const select = foreignKeys.map((k) => sql.identifier(k.name));
107107
const query = parentRow

src/PostgraphileNestedMutationsPlugin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ module.exports = function PostGraphileNestedMutationPlugin(builder) {
322322
if (identifiers.length !== primaryKeys.length) {
323323
throw new Error('Invalid ID');
324324
}
325-
condition = sql.fragment`${sql.join(
325+
condition = sql.fragment`(${sql.join(
326326
table.primaryKeyConstraint.keyAttributes.map(
327327
(key, idx) =>
328328
sql.fragment`${sql.identifier(key.name)} = ${gql2pg(
@@ -332,7 +332,7 @@ module.exports = function PostGraphileNestedMutationPlugin(builder) {
332332
)}`,
333333
),
334334
') and (',
335-
)}`;
335+
)})`;
336336
} catch (e) {
337337
debug(e);
338338
throw e;
@@ -486,15 +486,15 @@ module.exports = function PostGraphileNestedMutationPlugin(builder) {
486486
await Promise.all(
487487
updaterField.map(async (node) => {
488488
const where = sql.fragment`
489-
${sql.join(
489+
(${sql.join(
490490
keys.map(
491491
(k, i) =>
492492
sql.fragment`${sql.identifier(k.name)} = ${sql.value(
493493
row[foreignKeys[i].name],
494494
)}`,
495495
),
496496
') and (',
497-
)}
497+
)})
498498
`;
499499
const updatedRow = await pgNestedTableUpdate({
500500
nestedField,

src/PostgraphileNestedUpdatersPlugin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module.exports = function PostGraphileNestedUpdatersPlugin(builder) {
9292
if (identifiers.length !== primaryKeys.length) {
9393
throw new Error('Invalid ID');
9494
}
95-
keyWhere = sql.fragment`${sql.join(
95+
keyWhere = sql.fragment`(${sql.join(
9696
primaryKeys.map(
9797
(key, idx) =>
9898
sql.fragment`${sql.identifier(key.name)} = ${gql2pg(
@@ -102,10 +102,10 @@ module.exports = function PostGraphileNestedUpdatersPlugin(builder) {
102102
)}`,
103103
),
104104
') and (',
105-
)}`;
105+
)})`;
106106
} else {
107107
const foreignPrimaryKeys = constraint.keyAttributes;
108-
keyWhere = sql.fragment`${sql.join(
108+
keyWhere = sql.fragment`(${sql.join(
109109
foreignPrimaryKeys.map(
110110
(k) => sql.fragment`
111111
${sql.identifier(k.name)} = ${gql2pg(
@@ -116,7 +116,7 @@ module.exports = function PostGraphileNestedUpdatersPlugin(builder) {
116116
`,
117117
),
118118
') and (',
119-
)}`;
119+
)})`;
120120
}
121121

122122
const patchField =

0 commit comments

Comments
 (0)