Skip to content

Commit 585f933

Browse files
author
Tim M
committed
unique generate mutations removal & added pk check
1 parent ae7b8d1 commit 585f933

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/PostGraphileManyDeletePlugin.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const PostGraphileManyDeletePlugin: T.Plugin = (
104104

105105
const tableTypeName = namedType.name;
106106
const uniqueConstraints = table.constraints.filter(
107-
con => con.type === 'u' || con.type === 'p'
107+
con => con.type === 'p'
108108
);
109109

110110
// Setup and add the GraphQL Payload Type
@@ -331,6 +331,8 @@ const PostGraphileManyDeletePlugin: T.Plugin = (
331331
let hasConstraintValue = false;
332332

333333
inputData.forEach((dataObj, i) => {
334+
let setOfRcvdDataHasPKValue = false;
335+
334336
relevantAttributes.forEach((attr: T.PgAttribute) => {
335337
const fieldName = inflection.column(attr);
336338
const dataValue = dataObj[fieldName];
@@ -348,9 +350,14 @@ const PostGraphileManyDeletePlugin: T.Plugin = (
348350
...sqlValues[i],
349351
gql2pg(dataValue, attr.type, attr.typeModifier)
350352
];
351-
if (isConstraintAttr) hasConstraintValue = true;
353+
if (isConstraintAttr) {
354+
setOfRcvdDataHasPKValue = true;
355+
}
352356
}
353357
});
358+
if (!setOfRcvdDataHasPKValue) {
359+
hasConstraintValue = false;
360+
}
354361
});
355362

356363
if (!hasConstraintValue) {

src/PostGraphileManyUpdatePlugin.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const PostGraphileManyUpdatePlugin: T.Plugin = (
104104

105105
const tableTypeName = namedType.name;
106106
const uniqueConstraints = table.constraints.filter(
107-
con => con.type === 'u' || con.type === 'p'
107+
con => con.type === 'p'
108108
);
109109

110110
// Setup and add the GraphQL Payload type
@@ -301,6 +301,8 @@ const PostGraphileManyUpdatePlugin: T.Plugin = (
301301
let hasConstraintValue = false;
302302

303303
inputData.forEach((dataObj, i) => {
304+
let setOfRcvdDataHasPKValue = false;
305+
304306
relevantAttributes.forEach((attr: T.PgAttribute) => {
305307
const fieldName = inflection.column(attr);
306308
const dataValue = dataObj[fieldName];
@@ -327,15 +329,19 @@ const PostGraphileManyUpdatePlugin: T.Plugin = (
327329
];
328330
if (!isConstraintAttr) {
329331
usedColSQLVals[i] = [...usedColSQLVals[i], sql.raw('true')];
332+
} else {
333+
setOfRcvdDataHasPKValue = true;
330334
}
331-
if (isConstraintAttr) hasConstraintValue = true;
332335
} else {
333336
sqlValues[i] = [...sqlValues[i], sql.raw('NULL')];
334337
if (!isConstraintAttr) {
335338
usedColSQLVals[i] = [...usedColSQLVals[i], sql.raw('false')];
336339
}
337340
}
338341
});
342+
if (!setOfRcvdDataHasPKValue) {
343+
hasConstraintValue = false;
344+
}
339345
});
340346

341347
if (!hasConstraintValue) {

0 commit comments

Comments
 (0)