graphile-bulk-mutations 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +197 -0
- package/augmentations.d.ts +102 -0
- package/augmentations.js +11 -0
- package/esm/augmentations.d.ts +102 -0
- package/esm/augmentations.js +9 -0
- package/esm/index.d.ts +30 -0
- package/esm/index.js +29 -0
- package/esm/plugins/BulkDeletePlugin.d.ts +13 -0
- package/esm/plugins/BulkDeletePlugin.js +181 -0
- package/esm/plugins/BulkInflectionPlugin.d.ts +9 -0
- package/esm/plugins/BulkInflectionPlugin.js +103 -0
- package/esm/plugins/BulkInsertPlugin.d.ts +21 -0
- package/esm/plugins/BulkInsertPlugin.js +214 -0
- package/esm/plugins/BulkRelationalPlugin.d.ts +31 -0
- package/esm/plugins/BulkRelationalPlugin.js +127 -0
- package/esm/plugins/BulkTypesPlugin.d.ts +18 -0
- package/esm/plugins/BulkTypesPlugin.js +391 -0
- package/esm/plugins/BulkUpdatePlugin.d.ts +13 -0
- package/esm/plugins/BulkUpdatePlugin.js +211 -0
- package/esm/plugins/BulkUpsertPlugin.d.ts +12 -0
- package/esm/plugins/BulkUpsertPlugin.js +165 -0
- package/esm/plugins/index.d.ts +7 -0
- package/esm/plugins/index.js +7 -0
- package/esm/preset.d.ts +35 -0
- package/esm/preset.js +74 -0
- package/esm/types.d.ts +40 -0
- package/esm/types.js +7 -0
- package/esm/utils/index.d.ts +4 -0
- package/esm/utils/index.js +2 -0
- package/esm/utils/relations.d.ts +42 -0
- package/esm/utils/relations.js +83 -0
- package/esm/utils/sql-builder.d.ts +56 -0
- package/esm/utils/sql-builder.js +121 -0
- package/index.d.ts +30 -0
- package/index.js +44 -0
- package/package.json +61 -0
- package/plugins/BulkDeletePlugin.d.ts +13 -0
- package/plugins/BulkDeletePlugin.js +184 -0
- package/plugins/BulkInflectionPlugin.d.ts +9 -0
- package/plugins/BulkInflectionPlugin.js +106 -0
- package/plugins/BulkInsertPlugin.d.ts +21 -0
- package/plugins/BulkInsertPlugin.js +217 -0
- package/plugins/BulkRelationalPlugin.d.ts +31 -0
- package/plugins/BulkRelationalPlugin.js +130 -0
- package/plugins/BulkTypesPlugin.d.ts +18 -0
- package/plugins/BulkTypesPlugin.js +394 -0
- package/plugins/BulkUpdatePlugin.d.ts +13 -0
- package/plugins/BulkUpdatePlugin.js +214 -0
- package/plugins/BulkUpsertPlugin.d.ts +12 -0
- package/plugins/BulkUpsertPlugin.js +168 -0
- package/plugins/index.d.ts +7 -0
- package/plugins/index.js +17 -0
- package/preset.d.ts +35 -0
- package/preset.js +77 -0
- package/types.d.ts +40 -0
- package/types.js +10 -0
- package/utils/index.d.ts +4 -0
- package/utils/index.js +9 -0
- package/utils/relations.d.ts +42 -0
- package/utils/relations.js +86 -0
- package/utils/sql-builder.d.ts +56 -0
- package/utils/sql-builder.js +126 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
|
|
4
|
+
Copyright (c) 2025 Constructive <developers@constructive.io>
|
|
5
|
+
Copyright (c) 2020-present, Interweb, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# graphile-bulk-mutations
|
|
2
|
+
|
|
3
|
+
<p align="center" width="100%">
|
|
4
|
+
<img height="250" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center" width="100%">
|
|
8
|
+
<a href="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml">
|
|
9
|
+
<img height="20" src="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml/badge.svg" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/constructive-io/constructive/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/graphile-bulk-mutations"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/constructive?filename=graphile%2Fgraphile-bulk-mutations%2Fpackage.json"/></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
PostGraphile v5 plugin for bulk insert, upsert, update, and delete mutations with ON CONFLICT handling.
|
|
16
|
+
|
|
17
|
+
Adds bulk mutation support to PostGraphile:
|
|
18
|
+
|
|
19
|
+
- **Bulk insert** with optional `ON CONFLICT DO NOTHING` (ignore duplicates)
|
|
20
|
+
- **Bulk upsert** with `ON CONFLICT DO UPDATE SET` (selective column updates)
|
|
21
|
+
- **Bulk update** with condition-based WHERE clauses
|
|
22
|
+
- **Bulk delete** with condition-based WHERE clauses
|
|
23
|
+
- Column-level SELECT grant safety (`RETURNING <pk>` + follow-up SELECT)
|
|
24
|
+
- PG parameter batching (auto-split at 32K limit)
|
|
25
|
+
- Opt-in via smart tags (`@behavior +bulkInsert +bulkUpsert +bulkUpdate +bulkDelete`)
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { BulkMutationPreset } from 'graphile-bulk-mutations';
|
|
31
|
+
|
|
32
|
+
const preset: GraphileConfig.Preset = {
|
|
33
|
+
extends: [
|
|
34
|
+
BulkMutationPreset(),
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Per-Table Opt-In
|
|
40
|
+
|
|
41
|
+
Tables must opt in via smart tags — no bulk mutations are generated by default:
|
|
42
|
+
|
|
43
|
+
```sql
|
|
44
|
+
COMMENT ON TABLE users IS E'@behavior +bulkInsert +bulkUpsert +bulkUpdate +bulkDelete';
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
You can enable specific operations per table:
|
|
48
|
+
|
|
49
|
+
```sql
|
|
50
|
+
COMMENT ON TABLE orders IS E'@behavior +bulkInsert +bulkUpdate';
|
|
51
|
+
COMMENT ON TABLE categories IS E'@behavior +bulkInsert +bulkUpsert';
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Example Queries
|
|
55
|
+
|
|
56
|
+
### Bulk Insert
|
|
57
|
+
|
|
58
|
+
```graphql
|
|
59
|
+
mutation {
|
|
60
|
+
bulkCreateUsers(input: {
|
|
61
|
+
values: [
|
|
62
|
+
{ name: "Alice", email: "alice@example.com" }
|
|
63
|
+
{ name: "Bob", email: "bob@example.com" }
|
|
64
|
+
]
|
|
65
|
+
}) {
|
|
66
|
+
affectedCount
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Bulk Insert with ON CONFLICT DO NOTHING
|
|
72
|
+
|
|
73
|
+
```graphql
|
|
74
|
+
mutation {
|
|
75
|
+
bulkCreateUsers(input: {
|
|
76
|
+
values: [
|
|
77
|
+
{ name: "Alice", email: "alice@example.com" }
|
|
78
|
+
]
|
|
79
|
+
onConflict: {
|
|
80
|
+
constraint: USERS_EMAIL_KEY
|
|
81
|
+
action: IGNORE
|
|
82
|
+
}
|
|
83
|
+
}) {
|
|
84
|
+
affectedCount
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Bulk Upsert
|
|
90
|
+
|
|
91
|
+
```graphql
|
|
92
|
+
mutation {
|
|
93
|
+
bulkUpsertUsers(input: {
|
|
94
|
+
values: [
|
|
95
|
+
{ name: "Alice Updated", email: "alice@example.com" }
|
|
96
|
+
]
|
|
97
|
+
onConflict: {
|
|
98
|
+
constraint: USERS_EMAIL_KEY
|
|
99
|
+
}
|
|
100
|
+
}) {
|
|
101
|
+
affectedCount
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Bulk Update
|
|
107
|
+
|
|
108
|
+
```graphql
|
|
109
|
+
mutation {
|
|
110
|
+
bulkUpdateUsers(input: {
|
|
111
|
+
where: { name: "Alice" }
|
|
112
|
+
patch: { name: "Alice Updated" }
|
|
113
|
+
}) {
|
|
114
|
+
affectedCount
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Bulk Delete
|
|
120
|
+
|
|
121
|
+
```graphql
|
|
122
|
+
mutation {
|
|
123
|
+
bulkDeleteUsers(input: {
|
|
124
|
+
where: { name: "Bob" }
|
|
125
|
+
}) {
|
|
126
|
+
affectedCount
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Configuration
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
BulkMutationPreset({
|
|
135
|
+
bulkMaxRows: 1000, // Max rows per insert/upsert (default: 1000)
|
|
136
|
+
bulkRequireWhere: true, // Require WHERE on update/delete (default: true)
|
|
137
|
+
bulkNaming: 'bulk', // Naming strategy: 'bulk' | 'pluralized' | 'many'
|
|
138
|
+
})
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Education and Tutorials
|
|
144
|
+
|
|
145
|
+
1. 🚀 [Quickstart: Getting Up and Running](https://constructive.io/learn/quickstart)
|
|
146
|
+
Get started with modular databases in minutes. Install prerequisites and deploy your first module.
|
|
147
|
+
|
|
148
|
+
2. 📦 [Modular PostgreSQL Development with Database Packages](https://constructive.io/learn/modular-postgres)
|
|
149
|
+
Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.
|
|
150
|
+
|
|
151
|
+
3. ✏️ [Authoring Database Changes](https://constructive.io/learn/authoring-database-changes)
|
|
152
|
+
Master the workflow for adding, organizing, and managing database changes with pgpm.
|
|
153
|
+
|
|
154
|
+
4. 🧪 [End-to-End PostgreSQL Testing with TypeScript](https://constructive.io/learn/e2e-postgres-testing)
|
|
155
|
+
Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.
|
|
156
|
+
|
|
157
|
+
5. ⚡ [Supabase Testing](https://constructive.io/learn/supabase)
|
|
158
|
+
Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.
|
|
159
|
+
|
|
160
|
+
6. 💧 [Drizzle ORM Testing](https://constructive.io/learn/drizzle-testing)
|
|
161
|
+
Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.
|
|
162
|
+
|
|
163
|
+
7. 🔧 [Troubleshooting](https://constructive.io/learn/troubleshooting)
|
|
164
|
+
Common issues and solutions for pgpm, PostgreSQL, and testing.
|
|
165
|
+
|
|
166
|
+
## Related Constructive Tooling
|
|
167
|
+
|
|
168
|
+
### 📦 Package Management
|
|
169
|
+
|
|
170
|
+
* [pgpm](https://github.com/constructive-io/constructive/tree/main/pgpm/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
|
|
171
|
+
|
|
172
|
+
### 🧪 Testing
|
|
173
|
+
|
|
174
|
+
* [pgsql-test](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
|
|
175
|
+
* [pgsql-seed](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-seed): **🌱 PostgreSQL seeding utilities** for CSV, JSON, SQL data loading, and pgpm deployment.
|
|
176
|
+
* [supabase-test](https://github.com/constructive-io/constructive/tree/main/postgres/supabase-test): **🧪 Supabase-native test harness** preconfigured for the local Supabase stack—per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
|
|
177
|
+
* [graphile-test](https://github.com/constructive-io/constructive/tree/main/graphile/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
|
|
178
|
+
* [pg-query-context](https://github.com/constructive-io/constructive/tree/main/postgres/pg-query-context): **🔒 Session context injection** to add session-local context (e.g., `SET LOCAL`) into queries—ideal for setting `role`, `jwt.claims`, and other session settings.
|
|
179
|
+
|
|
180
|
+
### 🧠 Parsing & AST
|
|
181
|
+
|
|
182
|
+
* [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
|
|
183
|
+
* [libpg-query-node](https://www.npmjs.com/package/libpg-query): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
|
|
184
|
+
* [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
|
|
185
|
+
* [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
|
|
186
|
+
* [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
|
|
187
|
+
* [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
|
|
188
|
+
|
|
189
|
+
## Credits
|
|
190
|
+
|
|
191
|
+
**🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
|
|
192
|
+
|
|
193
|
+
## Disclaimer
|
|
194
|
+
|
|
195
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
196
|
+
|
|
197
|
+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript namespace augmentations for graphile-bulk-mutations.
|
|
3
|
+
*
|
|
4
|
+
* Extends the Graphile type system so that custom inflection methods,
|
|
5
|
+
* build properties, scope properties, schema options, and behaviors
|
|
6
|
+
* are recognized by the TypeScript compiler.
|
|
7
|
+
*/
|
|
8
|
+
import 'graphile-build';
|
|
9
|
+
import 'graphile-build-pg';
|
|
10
|
+
import type { BulkNamingStrategy } from './types';
|
|
11
|
+
declare global {
|
|
12
|
+
namespace GraphileBuild {
|
|
13
|
+
interface Inflection {
|
|
14
|
+
/** Bulk insert mutation name, e.g. "bulkCreateUser" */
|
|
15
|
+
bulkInsertField(this: Inflection, resourceName: string): string;
|
|
16
|
+
/** Bulk upsert mutation name, e.g. "bulkUpsertUser" */
|
|
17
|
+
bulkUpsertField(this: Inflection, resourceName: string): string;
|
|
18
|
+
/** Bulk update mutation name, e.g. "bulkUpdateUser" */
|
|
19
|
+
bulkUpdateField(this: Inflection, resourceName: string): string;
|
|
20
|
+
/** Bulk delete mutation name, e.g. "bulkDeleteUser" */
|
|
21
|
+
bulkDeleteField(this: Inflection, resourceName: string): string;
|
|
22
|
+
/** Payload type name, e.g. "BulkCreateUserPayload" */
|
|
23
|
+
bulkInsertPayloadType(this: Inflection, typeName: string): string;
|
|
24
|
+
/** Payload type name, e.g. "BulkUpsertUserPayload" */
|
|
25
|
+
bulkUpsertPayloadType(this: Inflection, typeName: string): string;
|
|
26
|
+
/** Payload type name, e.g. "BulkUpdateUserPayload" */
|
|
27
|
+
bulkUpdatePayloadType(this: Inflection, typeName: string): string;
|
|
28
|
+
/** Payload type name, e.g. "BulkDeleteUserPayload" */
|
|
29
|
+
bulkDeletePayloadType(this: Inflection, typeName: string): string;
|
|
30
|
+
/** Input type for bulk create values, e.g. "BulkCreateUserInput" */
|
|
31
|
+
bulkInsertInputType(this: Inflection, typeName: string): string;
|
|
32
|
+
/** Input type for bulk upsert values, e.g. "BulkUpsertUserInput" */
|
|
33
|
+
bulkUpsertInputType(this: Inflection, typeName: string): string;
|
|
34
|
+
/** Input type for bulk update, e.g. "BulkUpdateUserInput" */
|
|
35
|
+
bulkUpdateInputType(this: Inflection, typeName: string): string;
|
|
36
|
+
/** Input type for bulk delete, e.g. "BulkDeleteUserInput" */
|
|
37
|
+
bulkDeleteInputType(this: Inflection, typeName: string): string;
|
|
38
|
+
/** Per-table unique constraint enum, e.g. "UserUniqueConstraint" */
|
|
39
|
+
uniqueConstraintEnumType(this: Inflection, typeName: string): string;
|
|
40
|
+
/** Per-table column enum, e.g. "UserColumn" */
|
|
41
|
+
columnEnumType(this: Inflection, typeName: string): string;
|
|
42
|
+
/** ON CONFLICT input for insert, e.g. "BulkCreateUserOnConflictInput" */
|
|
43
|
+
bulkInsertOnConflictInputType(this: Inflection, typeName: string): string;
|
|
44
|
+
/** ON CONFLICT input for upsert, e.g. "BulkUpsertUserOnConflictInput" */
|
|
45
|
+
bulkUpsertOnConflictInputType(this: Inflection, typeName: string): string;
|
|
46
|
+
/** Values item input type, e.g. "UserBulkCreateItem" */
|
|
47
|
+
bulkInsertValuesItemType(this: Inflection, typeName: string): string;
|
|
48
|
+
/** Values item input type for upsert, e.g. "UserBulkUpsertItem" */
|
|
49
|
+
bulkUpsertValuesItemType(this: Inflection, typeName: string): string;
|
|
50
|
+
/** Nested values item type for relational inserts */
|
|
51
|
+
bulkNestedValuesItemType(this: Inflection, parentTypeName: string, childTypeName: string): string;
|
|
52
|
+
}
|
|
53
|
+
interface BehaviorStrings {
|
|
54
|
+
bulkInsert: true;
|
|
55
|
+
bulkUpsert: true;
|
|
56
|
+
bulkUpdate: true;
|
|
57
|
+
bulkDelete: true;
|
|
58
|
+
}
|
|
59
|
+
interface ScopeEnum {
|
|
60
|
+
isBulkMutationConstraintEnum?: boolean;
|
|
61
|
+
isBulkMutationColumnEnum?: boolean;
|
|
62
|
+
}
|
|
63
|
+
interface ScopeObject {
|
|
64
|
+
isBulkMutationPayload?: boolean;
|
|
65
|
+
}
|
|
66
|
+
interface ScopeObjectFieldsField {
|
|
67
|
+
isBulkMutationPayloadReturningField?: boolean;
|
|
68
|
+
isBulkMutationPayloadAffectedCountField?: boolean;
|
|
69
|
+
}
|
|
70
|
+
interface ScopeInputObject {
|
|
71
|
+
isBulkMutationInput?: boolean;
|
|
72
|
+
isBulkMutationOnConflictInput?: boolean;
|
|
73
|
+
isBulkMutationValuesItem?: boolean;
|
|
74
|
+
isBulkRelationalNestedInput?: boolean;
|
|
75
|
+
/** Resource name for relation discovery in BulkRelationalPlugin */
|
|
76
|
+
bulkMutationResourceName?: string;
|
|
77
|
+
}
|
|
78
|
+
interface SchemaOptions {
|
|
79
|
+
bulkNaming?: BulkNamingStrategy;
|
|
80
|
+
bulkInsert?: boolean;
|
|
81
|
+
bulkUpsert?: boolean;
|
|
82
|
+
bulkUpdate?: boolean;
|
|
83
|
+
bulkDelete?: boolean;
|
|
84
|
+
bulkRelational?: boolean;
|
|
85
|
+
bulkReturning?: boolean;
|
|
86
|
+
bulkMaxRows?: number;
|
|
87
|
+
bulkMaxNestingDepth?: number;
|
|
88
|
+
bulkRequireWhere?: boolean;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
namespace GraphileConfig {
|
|
92
|
+
interface Plugins {
|
|
93
|
+
BulkInflectionPlugin: true;
|
|
94
|
+
BulkTypesPlugin: true;
|
|
95
|
+
BulkInsertPlugin: true;
|
|
96
|
+
BulkUpsertPlugin: true;
|
|
97
|
+
BulkUpdatePlugin: true;
|
|
98
|
+
BulkDeletePlugin: true;
|
|
99
|
+
BulkRelationalPlugin: true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
package/augmentations.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TypeScript namespace augmentations for graphile-bulk-mutations.
|
|
4
|
+
*
|
|
5
|
+
* Extends the Graphile type system so that custom inflection methods,
|
|
6
|
+
* build properties, scope properties, schema options, and behaviors
|
|
7
|
+
* are recognized by the TypeScript compiler.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
require("graphile-build");
|
|
11
|
+
require("graphile-build-pg");
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript namespace augmentations for graphile-bulk-mutations.
|
|
3
|
+
*
|
|
4
|
+
* Extends the Graphile type system so that custom inflection methods,
|
|
5
|
+
* build properties, scope properties, schema options, and behaviors
|
|
6
|
+
* are recognized by the TypeScript compiler.
|
|
7
|
+
*/
|
|
8
|
+
import 'graphile-build';
|
|
9
|
+
import 'graphile-build-pg';
|
|
10
|
+
import type { BulkNamingStrategy } from './types';
|
|
11
|
+
declare global {
|
|
12
|
+
namespace GraphileBuild {
|
|
13
|
+
interface Inflection {
|
|
14
|
+
/** Bulk insert mutation name, e.g. "bulkCreateUser" */
|
|
15
|
+
bulkInsertField(this: Inflection, resourceName: string): string;
|
|
16
|
+
/** Bulk upsert mutation name, e.g. "bulkUpsertUser" */
|
|
17
|
+
bulkUpsertField(this: Inflection, resourceName: string): string;
|
|
18
|
+
/** Bulk update mutation name, e.g. "bulkUpdateUser" */
|
|
19
|
+
bulkUpdateField(this: Inflection, resourceName: string): string;
|
|
20
|
+
/** Bulk delete mutation name, e.g. "bulkDeleteUser" */
|
|
21
|
+
bulkDeleteField(this: Inflection, resourceName: string): string;
|
|
22
|
+
/** Payload type name, e.g. "BulkCreateUserPayload" */
|
|
23
|
+
bulkInsertPayloadType(this: Inflection, typeName: string): string;
|
|
24
|
+
/** Payload type name, e.g. "BulkUpsertUserPayload" */
|
|
25
|
+
bulkUpsertPayloadType(this: Inflection, typeName: string): string;
|
|
26
|
+
/** Payload type name, e.g. "BulkUpdateUserPayload" */
|
|
27
|
+
bulkUpdatePayloadType(this: Inflection, typeName: string): string;
|
|
28
|
+
/** Payload type name, e.g. "BulkDeleteUserPayload" */
|
|
29
|
+
bulkDeletePayloadType(this: Inflection, typeName: string): string;
|
|
30
|
+
/** Input type for bulk create values, e.g. "BulkCreateUserInput" */
|
|
31
|
+
bulkInsertInputType(this: Inflection, typeName: string): string;
|
|
32
|
+
/** Input type for bulk upsert values, e.g. "BulkUpsertUserInput" */
|
|
33
|
+
bulkUpsertInputType(this: Inflection, typeName: string): string;
|
|
34
|
+
/** Input type for bulk update, e.g. "BulkUpdateUserInput" */
|
|
35
|
+
bulkUpdateInputType(this: Inflection, typeName: string): string;
|
|
36
|
+
/** Input type for bulk delete, e.g. "BulkDeleteUserInput" */
|
|
37
|
+
bulkDeleteInputType(this: Inflection, typeName: string): string;
|
|
38
|
+
/** Per-table unique constraint enum, e.g. "UserUniqueConstraint" */
|
|
39
|
+
uniqueConstraintEnumType(this: Inflection, typeName: string): string;
|
|
40
|
+
/** Per-table column enum, e.g. "UserColumn" */
|
|
41
|
+
columnEnumType(this: Inflection, typeName: string): string;
|
|
42
|
+
/** ON CONFLICT input for insert, e.g. "BulkCreateUserOnConflictInput" */
|
|
43
|
+
bulkInsertOnConflictInputType(this: Inflection, typeName: string): string;
|
|
44
|
+
/** ON CONFLICT input for upsert, e.g. "BulkUpsertUserOnConflictInput" */
|
|
45
|
+
bulkUpsertOnConflictInputType(this: Inflection, typeName: string): string;
|
|
46
|
+
/** Values item input type, e.g. "UserBulkCreateItem" */
|
|
47
|
+
bulkInsertValuesItemType(this: Inflection, typeName: string): string;
|
|
48
|
+
/** Values item input type for upsert, e.g. "UserBulkUpsertItem" */
|
|
49
|
+
bulkUpsertValuesItemType(this: Inflection, typeName: string): string;
|
|
50
|
+
/** Nested values item type for relational inserts */
|
|
51
|
+
bulkNestedValuesItemType(this: Inflection, parentTypeName: string, childTypeName: string): string;
|
|
52
|
+
}
|
|
53
|
+
interface BehaviorStrings {
|
|
54
|
+
bulkInsert: true;
|
|
55
|
+
bulkUpsert: true;
|
|
56
|
+
bulkUpdate: true;
|
|
57
|
+
bulkDelete: true;
|
|
58
|
+
}
|
|
59
|
+
interface ScopeEnum {
|
|
60
|
+
isBulkMutationConstraintEnum?: boolean;
|
|
61
|
+
isBulkMutationColumnEnum?: boolean;
|
|
62
|
+
}
|
|
63
|
+
interface ScopeObject {
|
|
64
|
+
isBulkMutationPayload?: boolean;
|
|
65
|
+
}
|
|
66
|
+
interface ScopeObjectFieldsField {
|
|
67
|
+
isBulkMutationPayloadReturningField?: boolean;
|
|
68
|
+
isBulkMutationPayloadAffectedCountField?: boolean;
|
|
69
|
+
}
|
|
70
|
+
interface ScopeInputObject {
|
|
71
|
+
isBulkMutationInput?: boolean;
|
|
72
|
+
isBulkMutationOnConflictInput?: boolean;
|
|
73
|
+
isBulkMutationValuesItem?: boolean;
|
|
74
|
+
isBulkRelationalNestedInput?: boolean;
|
|
75
|
+
/** Resource name for relation discovery in BulkRelationalPlugin */
|
|
76
|
+
bulkMutationResourceName?: string;
|
|
77
|
+
}
|
|
78
|
+
interface SchemaOptions {
|
|
79
|
+
bulkNaming?: BulkNamingStrategy;
|
|
80
|
+
bulkInsert?: boolean;
|
|
81
|
+
bulkUpsert?: boolean;
|
|
82
|
+
bulkUpdate?: boolean;
|
|
83
|
+
bulkDelete?: boolean;
|
|
84
|
+
bulkRelational?: boolean;
|
|
85
|
+
bulkReturning?: boolean;
|
|
86
|
+
bulkMaxRows?: number;
|
|
87
|
+
bulkMaxNestingDepth?: number;
|
|
88
|
+
bulkRequireWhere?: boolean;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
namespace GraphileConfig {
|
|
92
|
+
interface Plugins {
|
|
93
|
+
BulkInflectionPlugin: true;
|
|
94
|
+
BulkTypesPlugin: true;
|
|
95
|
+
BulkInsertPlugin: true;
|
|
96
|
+
BulkUpsertPlugin: true;
|
|
97
|
+
BulkUpdatePlugin: true;
|
|
98
|
+
BulkDeletePlugin: true;
|
|
99
|
+
BulkRelationalPlugin: true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript namespace augmentations for graphile-bulk-mutations.
|
|
3
|
+
*
|
|
4
|
+
* Extends the Graphile type system so that custom inflection methods,
|
|
5
|
+
* build properties, scope properties, schema options, and behaviors
|
|
6
|
+
* are recognized by the TypeScript compiler.
|
|
7
|
+
*/
|
|
8
|
+
import 'graphile-build';
|
|
9
|
+
import 'graphile-build-pg';
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* graphile-bulk-mutations
|
|
3
|
+
*
|
|
4
|
+
* A PostGraphile v5 plugin for bulk insert, upsert, update, and delete
|
|
5
|
+
* mutations with ON CONFLICT handling.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { BulkMutationPreset } from 'graphile-bulk-mutations';
|
|
10
|
+
*
|
|
11
|
+
* const preset = {
|
|
12
|
+
* extends: [
|
|
13
|
+
* BulkMutationPreset(),
|
|
14
|
+
* ],
|
|
15
|
+
* };
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* Tables must opt in via smart tags:
|
|
19
|
+
* ```sql
|
|
20
|
+
* COMMENT ON TABLE users IS E'@behavior +bulkInsert +bulkUpsert';
|
|
21
|
+
* COMMENT ON TABLE orders IS E'@behavior +bulkInsert +bulkUpdate +bulkDelete';
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
import './augmentations';
|
|
25
|
+
export { BulkMutationPreset } from './preset';
|
|
26
|
+
export { BulkDeletePlugin, BulkInflectionPlugin, BulkInsertPlugin, BulkRelationalPlugin, BulkTypesPlugin, BulkUpdatePlugin, BulkUpsertPlugin } from './plugins';
|
|
27
|
+
export type { BulkMutationOptions, BulkNamingStrategy } from './types';
|
|
28
|
+
export { PG_MAX_PARAMS } from './types';
|
|
29
|
+
export type { ColumnSpec, InsertBatch } from './utils';
|
|
30
|
+
export { buildBulkDeleteSQL, buildBulkInsertSQL, buildBulkUpdateSQL } from './utils';
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* graphile-bulk-mutations
|
|
3
|
+
*
|
|
4
|
+
* A PostGraphile v5 plugin for bulk insert, upsert, update, and delete
|
|
5
|
+
* mutations with ON CONFLICT handling.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { BulkMutationPreset } from 'graphile-bulk-mutations';
|
|
10
|
+
*
|
|
11
|
+
* const preset = {
|
|
12
|
+
* extends: [
|
|
13
|
+
* BulkMutationPreset(),
|
|
14
|
+
* ],
|
|
15
|
+
* };
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* Tables must opt in via smart tags:
|
|
19
|
+
* ```sql
|
|
20
|
+
* COMMENT ON TABLE users IS E'@behavior +bulkInsert +bulkUpsert';
|
|
21
|
+
* COMMENT ON TABLE orders IS E'@behavior +bulkInsert +bulkUpdate +bulkDelete';
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
import './augmentations';
|
|
25
|
+
export { BulkMutationPreset } from './preset';
|
|
26
|
+
// Re-export all plugins for granular use
|
|
27
|
+
export { BulkDeletePlugin, BulkInflectionPlugin, BulkInsertPlugin, BulkRelationalPlugin, BulkTypesPlugin, BulkUpdatePlugin, BulkUpsertPlugin } from './plugins';
|
|
28
|
+
export { PG_MAX_PARAMS } from './types';
|
|
29
|
+
export { buildBulkDeleteSQL, buildBulkInsertSQL, buildBulkUpdateSQL } from './utils';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import '../augmentations';
|
|
2
|
+
import type { GraphileConfig } from 'graphile-config';
|
|
3
|
+
/**
|
|
4
|
+
* BulkDeletePlugin
|
|
5
|
+
*
|
|
6
|
+
* Registers `bulkDeleteX` mutation fields for each resource with the
|
|
7
|
+
* `bulkDelete` behavior. Uses DELETE ... WHERE with conditions from
|
|
8
|
+
* graphile-connection-filter (or PostGraphile's built-in condition type).
|
|
9
|
+
*
|
|
10
|
+
* Uses `RETURNING <pk_columns>` (not `RETURNING *`) + follow-up SELECT
|
|
11
|
+
* to respect column-level SELECT grants.
|
|
12
|
+
*/
|
|
13
|
+
export declare const BulkDeletePlugin: GraphileConfig.Plugin;
|