Skip to content

Commit ae7b8d1

Browse files
author
Tim M
committed
initial commit
0 parents  commit ae7b8d1

31 files changed

Lines changed: 6536 additions & 0 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"semi": true
3+
}

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# postgraphile-plugin-many-create-update-delete
2+
3+
<!-- ![npm](https://img.shields.io/npm/v/postgraphile-plugin-many-create-update-delete) -->
4+
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
5+
6+
This plugin implements mutations that allow many creates, updates, and deletes in a single transaction.
7+
8+
## Getting Started
9+
10+
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.
11+
12+
## Plugin Options
13+
14+
This plugin respects the default option to disable mutations all together via ```graphileBuildOptions```.
15+
16+
```js
17+
postgraphile(pgConfig, schema, {
18+
graphileBuildOptions: {
19+
pgDisableDefaultMutations: true
20+
}
21+
});
22+
```
23+
24+
## Smart Comments
25+
26+
You must use smart comments to enable the many create, update, and delete mutations for a table, since they are not enabled by default to prevent crowding with the other autogenerated postgraphile default mutations. The single tag ```@mncud``` is all that's needed.
27+
28+
```sql
29+
comment on table public."Test" is
30+
E'@mncud The test table is just for showing this example with comments.';
31+
```
32+
33+
## Usage
34+
35+
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.
36+
37+
### 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.
39+
40+
### 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.
42+
43+
### 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.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as T from './pluginTypes';
2+
declare const PostGraphileManyCreatePlugin: T.Plugin;
3+
export default PostGraphileManyCreatePlugin;
4+
//# sourceMappingURL=PostGraphileManyCreatePlugin.d.ts.map

build/PostGraphileManyCreatePlugin.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/PostGraphileManyCreatePlugin.js

Lines changed: 198 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)