@stonecrop/graphql-middleware 0.29.0 → 0.30.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/dist/index.js +310 -302
- package/dist/index.js.map +1 -1
- package/dist/src/plugin/postgraphile.d.ts.map +1 -1
- package/dist/src/plugin/postgraphile.js +24 -2
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgraphile.d.ts","sourceRoot":"","sources":["../../../src/plugin/postgraphile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,WAAW,EAAiD,MAAM,mBAAmB,CAAA;AAGjH,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,cAAc,CAAA;AAExD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAW5D;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACpC;;;;;;;;;;;;;;;;;;OAkBG;IACH,QAAQ,EAAE,QAAQ,CAAA;IAClB,4EAA4E;IAC5E,OAAO,EAAE,MAAM,CAAA;IACf,iGAAiG;IACjG,MAAM,EAAE,MAAM,CAAA;IACd,yFAAyF;IACzF,IAAI,EAAE,WAAW,CAAA;IACjB,8GAA8G;IAC9G,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC1B;;;;;;OAMG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,wFAAwF;IACxF,IAAI,EAAE,OAAO,EAAE,CAAA;IACf,kGAAkG;IAClG,YAAY,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,oBAAoB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAE/E;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACtC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;;;;;;OAOG;IACH,MA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OAAO,CAAC,CAAA;AAE/E;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACtC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAA;IAC9D;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAClC;AAmCD;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAS,sBAA2B,KAAG,cAAc,CAAC,MAmuB3F,CAAA;AA0BD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAQvD;AAkID;;;;;GAKG"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { camelToSnake, getRecordIdField, resolveLinkRenderMode } from '@stonecrop/schema';
|
|
1
|
+
import { camelToSnake, getRecordIdField, resolveLinkRenderMode, unwrapInlineLinks } from '@stonecrop/schema';
|
|
2
2
|
import { loadOneWithPgClient, sideEffectWithPgClient } from '@dataplan/pg';
|
|
3
3
|
import { constant, lambda, object } from 'postgraphile/grafast';
|
|
4
4
|
import { extendSchema } from 'postgraphile/utils';
|
|
@@ -499,7 +499,13 @@ export const createStonecropPlugin = (options = {}) => {
|
|
|
499
499
|
};
|
|
500
500
|
// Record envelope: [{ id, data }] — the transition keys off the record id.
|
|
501
501
|
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- spec.actionArgs is a Grafast runtime value; record envelope shape is the dispatch contract
|
|
502
|
-
const
|
|
502
|
+
const rawArgs = (Array.isArray(spec.actionArgs) ? spec.actionArgs : []);
|
|
503
|
+
// An inline link arrives as `{ id, displayText }`; a column takes the id alone.
|
|
504
|
+
// Reduced here so no client has to know what storage accepts.
|
|
505
|
+
//
|
|
506
|
+
// The whole envelope, not just `recordData` below — handlers read `ctx.args`.
|
|
507
|
+
// Copied, not mutated: `spec.actionArgs` is the request's own value.
|
|
508
|
+
const argList = rawArgs.map(entry => entry?.data ? { ...entry, data: unwrapInlineLinks(meta.fields, entry.data) } : entry);
|
|
503
509
|
const recordId = argList[0]?.id;
|
|
504
510
|
const recordData = argList[0]?.data ?? {};
|
|
505
511
|
// The database author's effect for this action, if one is registered. Keyed
|
|
@@ -674,6 +680,22 @@ export const createStonecropPlugin = (options = {}) => {
|
|
|
674
680
|
// caller still gets `success: false` rather than a GraphQL error.
|
|
675
681
|
if (!outcome.success)
|
|
676
682
|
throw new ActionRolledBack(outcome);
|
|
683
|
+
// A record a write returns is a record, so it carries the links a read
|
|
684
|
+
// resolves. Enriching one path and not the other changes a record's
|
|
685
|
+
// shape depending on how the client came by it: a link rendered its
|
|
686
|
+
// display text until the record was saved, and its raw id from then
|
|
687
|
+
// until the next full fetch. Nothing fails — the field just goes wrong.
|
|
688
|
+
//
|
|
689
|
+
// Runs inside the transaction so the lookup sees the row just written,
|
|
690
|
+
// and only on success, since a rolled-back action returns no record.
|
|
691
|
+
// A result that is not a record at all — an effect's `{ state }` — has
|
|
692
|
+
// no field the doctype declares as an inline link, so it is untouched.
|
|
693
|
+
if (outcome.success && outcome.data !== null && typeof outcome.data === 'object') {
|
|
694
|
+
// A predicate rather than an assertion: an element that is not an object has
|
|
695
|
+
// no field to enrich, so dropping it is the honest answer.
|
|
696
|
+
const written = (Array.isArray(outcome.data) ? outcome.data : [outcome.data]).filter((row) => row !== null && typeof row === 'object');
|
|
697
|
+
await enrichLinkDisplayFields(tx, meta, written, options.tables, debugSql);
|
|
698
|
+
}
|
|
677
699
|
// Attached here rather than carried through `applyGuardedTransition`:
|
|
678
700
|
// which keys a backend can store is a storage question, and the
|
|
679
701
|
// dispatcher is deliberately storage-agnostic. A failed action wrote
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/graphql-middleware",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "GraphQL middleware for PostGraphile and Stonecrop schema",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@dataplan/pg": "^1.0.3",
|
|
23
23
|
"graphql": "^16.14.0",
|
|
24
24
|
"postgraphile": "^5.0.3",
|
|
25
|
-
"@stonecrop/schema": "0.
|
|
25
|
+
"@stonecrop/schema": "0.30.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@electric-sql/pglite": "^0.4.5",
|