@stonecrop/graphql-middleware 0.44.0 → 0.45.1

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 CHANGED
@@ -28,11 +28,11 @@ const preset: GraphileConfig.Preset = {
28
28
  }
29
29
  ```
30
30
 
31
- `createStonecropPreset()` makes two corrections to the schema PostGraphile would otherwise build.
32
- It moves Relay's global identifier to `nodeId` so a real `id` column keeps its own name, and it
33
- exposes the many side of any foreign key declared `ON DELETE CASCADE` — so a parent type carries a
34
- collection field for the rows it owns, and `stonecrop-schema generate` can turn that into a child
35
- table. A foreign key without a cascade is a reference, not ownership, and stays one-directional.
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`. Self-transitions (`selfTransition: true`) have no state target and no data-write path on this backend, so they are rejected rather than silently succeeding.
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, which is the Postgres adapter's position today; the two nuxt hosts implement it.
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
 
@@ -85,14 +85,18 @@ export declare interface ActionHandlerContext {
85
85
  * handler never overrides the guard.
86
86
  *
87
87
  * There are four action shapes this distinguishes:
88
+ *
88
89
  * - A cross-state **transition** (has `nextState`): writes the new `status`, guarded by `allowedStates`.
90
+ *
89
91
  * - A **self-transition** (`selfTransition: true`, no `nextState`, e.g. `Save`): stays in the current
90
92
  * state and persists record field `data` in place via `io.writeData`, guarded by `allowedStates`.
91
93
  * When the target record does not exist the same write creates it — saving a record is one
92
94
  * request whether or not the row is there yet, so there is no separate create action, no create
93
95
  * mutation, and no second write path for it.
96
+ *
94
97
  * - A **stateless command** (neither of the above) with an `io.runEffect`: the handler is the whole
95
98
  * outcome. Still guarded by `allowedStates`, and still forbidden from moving the record.
99
+ *
96
100
  * - Anything else — no `nextState`, no `selfTransition`, no registered effect — is either a genuine
97
101
  * authoring mistake or a command whose handler was never wired. It fails loudly before touching
98
102
  * the backend rather than reporting a false success.
@@ -163,7 +167,9 @@ export declare const createStonecropPlugin: (options?: StonecropPluginOptions) =
163
167
  * Creates a Stonecrop-flavoured PostGraphile preset.
164
168
  *
165
169
  * The returned preset extends `PostGraphileAmberPreset` and applies Stonecrop's
166
- * recommended defaults. Pass it to `extends` in your PostGraphile configuration:
170
+ * recommended defaults. It turns off the mutations Amber generates, a create, update and delete for
171
+ * every table and one for every `VOLATILE` database function, so `stonecropAction` is the only write
172
+ * the API offers. Pass it to `extends` in your PostGraphile configuration:
167
173
  *
168
174
  * ```typescript
169
175
  * import { createStonecropPreset, makePgService, createStonecropPlugin } from '@stonecrop/graphql-middleware'
@@ -228,6 +234,7 @@ export declare type FetchHandler = (pgClient: PgClient, parentRecord: Record<str
228
234
  * Controls how PostgreSQL column names are mapped to GraphQL field names in the synthesized preset.
229
235
  *
230
236
  * - `'camel'` (default): `my_column` → `myColumn`. This matches PostGraphile Amber's built-in behaviour.
237
+ *
231
238
  * - `'pascal'`: `my_column` → `MyColumn`. Opt in via `createStonecropPreset({ fieldCasing: 'pascal' })` or
232
239
  * `grafserv.fieldCasing: 'pascal'` in `nuxt.config.ts`.
233
240
  *
@@ -266,10 +273,9 @@ export declare interface GuardedTransitionIO {
266
273
  /**
267
274
  * Read the record's current workflow state — the value of its `status` field.
268
275
  *
269
- * Three answers, and the difference between the last two matters:
270
- * - a string — the record's current state
271
- * - `undefined` — the record exists but carries no workflow state
272
- * - `null` — **there is no such record**
276
+ * Three answers, and the difference between the last two matters: a string is the record's
277
+ * current state, `undefined` means the record exists but carries no workflow state, and `null`
278
+ * means **there is no such record**.
273
279
  *
274
280
  * Collapsing those two into `undefined` is what let an action against a missing record report
275
281
  * success: the state read as `''`, an action declaring no `allowedStates` passed the guard, and