@stonecrop/graphql-middleware 0.44.0 → 0.45.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/README.md +7 -7
- package/dist/graphql-middleware.d.ts +3 -1
- package/dist/index.js +400 -366
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -28,11 +28,11 @@ const preset: GraphileConfig.Preset = {
|
|
|
28
28
|
}
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
`createStonecropPreset()` makes
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
collection field for the rows it owns
|
|
35
|
-
|
|
31
|
+
`createStonecropPreset()` makes three changes to the schema PostGraphile would otherwise build:
|
|
32
|
+
|
|
33
|
+
- It moves Relay's global identifier to `nodeId`, so a real `id` column keeps its own name.
|
|
34
|
+
- It exposes the many side of any foreign key declared `ON DELETE CASCADE`, so a parent type carries a collection field for the rows it owns and `stonecrop-schema generate` can turn that into a child table. A foreign key without a cascade is a reference, not ownership, and stays one-directional.
|
|
35
|
+
- It turns off the mutations Amber generates, a create, update and delete for every table and one for every `VOLATILE` database function, so `stonecropAction` is the only write the API offers.
|
|
36
36
|
|
|
37
37
|
`createStonecropPlugin()` discovers the `PgExecutor` automatically from `pgServices` — no executor argument is needed. An optional `StonecropPluginOptions` object accepts:
|
|
38
38
|
|
|
@@ -153,13 +153,13 @@ Actions are declared per doctype in `workflow.actions`. Each action names the st
|
|
|
153
153
|
}
|
|
154
154
|
```
|
|
155
155
|
|
|
156
|
-
The `stonecropAction(doctype, action, args)` mutation dispatches through `applyGuardedTransition`: it reads the record's `status`, rejects the action if the current state is not in `allowedStates` (`isActionAllowedInState`), then writes `nextState`. The record is identified by `args[0].id`.
|
|
156
|
+
The `stonecropAction(doctype, action, args)` mutation dispatches through `applyGuardedTransition`: it reads the record's `status`, rejects the action if the current state is not in `allowedStates` (`isActionAllowedInState`), then writes `nextState`. The record is identified by `args[0].id`. A self-transition (`selfTransition: true`) keeps the state and writes the record's data instead: the Postgres adapter sets each declared field that has a column, except `status` and any column the database fills itself (a generated column, or an identity generated always), and lists each key it left out in `droppedFields`.
|
|
157
157
|
|
|
158
158
|
An action against a record that does not exist is reported as such, before the guard runs. This depends on the backend distinguishing the two things `undefined` used to mean — `GuardedTransitionIO.readState` returns `null` for a lookup that missed, and `undefined` only for a row that exists with no workflow state. A backend that returns `undefined` for both makes a bad id look like a workflow violation, or, when the action declares no `allowedStates`, makes it look like a success.
|
|
159
159
|
|
|
160
160
|
### Creating a record
|
|
161
161
|
|
|
162
|
-
There is no create mutation, no create action, and no separate create write. **Saving a record that does not exist creates it**, because "persist this record's data" is one request whether or not the row is there yet. `GuardedTransitionIO.writeData` is an upsert: it receives an `exists` flag the dispatcher already knows, having read the record's state to run the guard. A backend that omits `writeData` declines both saving and creating
|
|
162
|
+
There is no create mutation, no create action, and no separate create write. **Saving a record that does not exist creates it**, because "persist this record's data" is one request whether or not the row is there yet. `GuardedTransitionIO.writeData` is an upsert: it receives an `exists` flag the dispatcher already knows, having read the record's state to run the guard. A backend that omits `writeData` declines both saving and creating; the Postgres adapter and the two nuxt hosts implement it.
|
|
163
163
|
|
|
164
164
|
`allowedStates` is deliberately not consulted on creation — it constrains movement between states, and a record being created is not in one. Its initial state is the backend's to set. Only a self-transition creates: a `nextState` transition against a missing record is a bad id, not a request to create one.
|
|
165
165
|
|
|
@@ -163,7 +163,9 @@ export declare const createStonecropPlugin: (options?: StonecropPluginOptions) =
|
|
|
163
163
|
* Creates a Stonecrop-flavoured PostGraphile preset.
|
|
164
164
|
*
|
|
165
165
|
* The returned preset extends `PostGraphileAmberPreset` and applies Stonecrop's
|
|
166
|
-
* recommended defaults.
|
|
166
|
+
* recommended defaults. It turns off the mutations Amber generates, a create, update and delete for
|
|
167
|
+
* every table and one for every `VOLATILE` database function, so `stonecropAction` is the only write
|
|
168
|
+
* the API offers. Pass it to `extends` in your PostGraphile configuration:
|
|
167
169
|
*
|
|
168
170
|
* ```typescript
|
|
169
171
|
* import { createStonecropPreset, makePgService, createStonecropPlugin } from '@stonecrop/graphql-middleware'
|