Skip to content

Commit e3254a8

Browse files
author
Tim M
committed
add null return for invalid input data
1 parent 8de0aa0 commit e3254a8

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55

66
This plugin implements mutations that allow many creates, updates, and deletes in a single transaction.
77

8+
## Roadmap
9+
Work is ongoing, here's the plan:
10+
11+
- [ ] Add a test suite, CI, and better test example in the readme.
12+
- [ ] Update smart comments with better functionality to include individual create, update, or delete mutations vs. including them all together.
13+
- [ ] Add plugin options that allow conflict handling for inserts. This would allow updates (upsert), no action, failures (current default) based off the constraints or further options.
14+
- [ ] Add input types for the many updates and delete mutations, to show required constraints vs. using the table patch types that do not.
15+
- [ ] Add better returned payload options, preferably to return a list of modified records.
16+
- [ ] Add support for node id based updates and deletes.
17+
818
## Getting Started
919

1020
View the [postgraphile docs](https://www.graphile.org/postgraphile/extending/#loading-additional-plugins) for information about loading the plugin via the CLI or as a NodeJS library.
@@ -27,18 +37,18 @@ You must use smart comments to enable the many create, update, and delete mutati
2737

2838
```sql
2939
comment on table public."Test" is
30-
E'@mncud The test table is just for showing this example with comments.';
40+
E'@mncud\n The test table is just for showing this example with comments.';
3141
```
3242

3343
## Usage
3444

3545
The plugin creates new mutations that allow you to batch create, update, and delete items from a given table. It works with primary keys for updates and deletes using the input patch that postgraphile generates. All creates, updates, and deletes have scoped names with "mn" in front of the mutation name to prevent conflicts with other mutations.
3646

3747
### Creates
38-
```mnCreateTest``` would be an example mutation name, and we'll say it has attributes of test1 (a boolean), and name (a varchar). You'll see the required input has the clientMutationId and also a field called ```mnTest```, where ```mnTest``` will take an array of items that use the table input type. Since it uses the table input type, the required items are all listed as expected.
48+
```mnCreateTest``` would be an example mutation name, and we'll say it has attributes of test1 (a boolean), and name (a varchar). You'll see the required input has the clientMutationId and also a field called ```mnTest```, where ```mnTest``` will take an array of items that use the table input type. Since it uses the table input type, the required items are all listed as expected. When creating records, any attributes left off will have their values set to ```default```.
3949

4050
### Updates
41-
```mnUpdateTestByName``` would be the update example name, assuming the name is the primary key. Updates have a required input with the clientMutatationId and a patch. The patch field accepts an array of table patch items. You ***MUST*** provide the primary key within the patch items b/c that is what's used in the where clause to update the correct row.
51+
```mnUpdateTestByName``` would be the update example name, assuming the name is the primary key. Updates have a required input with the clientMutatationId and a patch. The patch field accepts an array of table patch items. You ***MUST*** provide the primary key within the patch items b/c that is what's used in the where clause to update the correct row(s). Attributes that are not provided in the list of provided values, will not be updated. With that said, you can update different attributes in one record and leave them off in another and it will update both as expected.
4252

4353
### Deletes
44-
```mnDeleteTestByName``` would be the delete example name. Deletes have a required input with the clientMutationId and a patch. The patch field accepts an array of table patch items, but only the primary key items are used. You ***MUST*** provide the primary key within the patch items b/c that is what's used in the where clause to update the correct row.
54+
```mnDeleteTestByName``` would be the delete example name. Deletes have a required input with the clientMutationId and a patch. The patch field accepts an array of table patch items, but only the primary key items are used. You ***MUST*** provide the primary key(s) within the patch items b/c that is what's used in the where clause to delete the correct row(s).

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postgraphile-plugin-many-create-update-delete",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Postgraphile plugin that enables many create, update, & delete mutations in a single transaction.",
55
"main": "build/index.js",
66
"repository": {

src/PostGraphileManyCreatePlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ const PostGraphileManyCreatePlugin: T.Plugin = (
253253
input[
254254
`mn${inflection.upperCamelCase(inflection.tableFieldName(table))}`
255255
];
256+
if (!inputData || inputData.length === 0) return null;
256257
const sqlValues: T.SQL[][] = Array(inputData.length).fill([]);
257258

258259
inputData.forEach((dataObj, i) => {

src/PostGraphileManyDeletePlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ const PostGraphileManyDeletePlugin: T.Plugin = (
327327
inflection.patchField(inflection.tableFieldName(table))
328328
)}`
329329
];
330+
if (!inputData || inputData.length === 0) return null;
330331
const sqlValues: T.SQL[][] = Array(inputData.length).fill([]);
331332
let hasConstraintValue = true;
332333

src/PostGraphileManyUpdatePlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ const PostGraphileManyUpdatePlugin: T.Plugin = (
294294
inflection.patchField(inflection.tableFieldName(table))
295295
)}`
296296
];
297+
if (!inputData || inputData.length === 0) return null;
297298
const sqlValues: T.SQL[][] = Array(inputData.length).fill([]);
298299

299300
const usedSQLColumns: T.SQL[] = [];

0 commit comments

Comments
 (0)