@stonecrop/graphql-middleware 0.18.0 → 0.19.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 +429 -381
- package/dist/index.js.map +1 -1
- package/dist/src/fields.d.ts +3 -17
- package/dist/src/fields.d.ts.map +1 -1
- package/dist/src/fields.js +7 -27
- package/dist/src/link-display.d.ts +19 -0
- package/dist/src/link-display.d.ts.map +1 -0
- package/dist/src/link-display.js +80 -0
- package/dist/src/plugin/postgraphile.d.ts +6 -0
- package/dist/src/plugin/postgraphile.d.ts.map +1 -1
- package/dist/src/plugin/postgraphile.js +15 -10
- package/dist/src/tables.d.ts +14 -0
- package/dist/src/tables.d.ts.map +1 -0
- package/dist/src/tables.js +21 -0
- package/dist/src/typeDefs.d.ts.map +1 -1
- package/dist/src/typeDefs.js +1 -0
- package/package.json +2 -2
package/dist/src/fields.d.ts
CHANGED
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
import type { DoctypeField,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Fieldset entries are replaced by their children; all other fields pass through.
|
|
5
|
-
*
|
|
6
|
-
* A fieldset is a layout grouping, not a scope: every field inside one is a field of the doctype,
|
|
7
|
-
* with a column of its own and a name a link can bind to. Anything asking "what does this doctype
|
|
8
|
-
* declare" must therefore descend, and the two ways to get that wrong point opposite ways — the
|
|
9
|
-
* SELECT builder would omit real columns, while a validator would report a working declaration as
|
|
10
|
-
* broken.
|
|
11
|
-
*
|
|
12
|
-
* Lives here rather than beside either caller because it now has three of them across two modules
|
|
13
|
-
* (`getSqlColumns` and `knownFields` in the plugin, `validateReferences` in the registry), and a
|
|
14
|
-
* second copy is how the plugin and the registry would come to disagree about what a doctype
|
|
15
|
-
* declares. Internal — not re-exported from the package index.
|
|
16
|
-
*/
|
|
17
|
-
export declare function flattenFields(fields: readonly DoctypeField[]): (ValueField | TableField)[];
|
|
1
|
+
import type { DoctypeField, ValueField } from '@stonecrop/schema';
|
|
2
|
+
import { flattenFields } from '@stonecrop/schema';
|
|
3
|
+
export { flattenFields };
|
|
18
4
|
/**
|
|
19
5
|
* The fields that have a database column of their own — the one definition of that question.
|
|
20
6
|
*
|
package/dist/src/fields.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../src/fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../src/fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAOjD,OAAO,EAAE,aAAa,EAAE,CAAA;AAExB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,UAAU,EAAE,CAEhF"}
|
package/dist/src/fields.js
CHANGED
|
@@ -1,30 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* SELECT builder would omit real columns, while a validator would report a working declaration as
|
|
9
|
-
* broken.
|
|
10
|
-
*
|
|
11
|
-
* Lives here rather than beside either caller because it now has three of them across two modules
|
|
12
|
-
* (`getSqlColumns` and `knownFields` in the plugin, `validateReferences` in the registry), and a
|
|
13
|
-
* second copy is how the plugin and the registry would come to disagree about what a doctype
|
|
14
|
-
* declares. Internal — not re-exported from the package index.
|
|
15
|
-
*/
|
|
16
|
-
export function flattenFields(fields) {
|
|
17
|
-
const result = [];
|
|
18
|
-
for (const f of fields) {
|
|
19
|
-
if (f.kind === 'fieldset') {
|
|
20
|
-
result.push(...flattenFields(f.schema));
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
result.push(f);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
1
|
+
import { flattenFields } from '@stonecrop/schema';
|
|
2
|
+
// Re-exported so this module stays the one place the adapter asks about a doctype's fields, while
|
|
3
|
+
// the definition itself lives in `@stonecrop/schema`. It moved there because `DoctypeMeta`'s own
|
|
4
|
+
// validation needs the same descent, and the copy it had written instead scanned top level only —
|
|
5
|
+
// so the load gate and the read path disagreed about what a doctype declares, which is exactly
|
|
6
|
+
// what keeping one definition is for.
|
|
7
|
+
export { flattenFields };
|
|
28
8
|
/**
|
|
29
9
|
* The fields that have a database column of their own — the one definition of that question.
|
|
30
10
|
*
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DoctypeMeta } from '@stonecrop/schema';
|
|
2
|
+
import type { PgClient } from '@dataplan/pg';
|
|
3
|
+
type SqlQueryFn = (pgClient: PgClient, query: {
|
|
4
|
+
text: string;
|
|
5
|
+
values?: unknown[];
|
|
6
|
+
}) => Promise<{
|
|
7
|
+
rows: readonly Record<string, unknown>[];
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Add `fieldname__display` alongside each inline foreign-key field when the target doctype
|
|
11
|
+
* declares a `displayField`. Scalar FK values only — expanded relations are skipped.
|
|
12
|
+
*
|
|
13
|
+
* Takes every row at once and issues one lookup per FK field, not per row. Callers holding a batch
|
|
14
|
+
* must pass the whole batch: called per row inside a loader's own loop it reinstates the N+1 the
|
|
15
|
+
* loader exists to prevent, and does so invisibly, since the result is identical either way.
|
|
16
|
+
*/
|
|
17
|
+
export declare function enrichLinkDisplayFields(pgClient: PgClient, meta: DoctypeMeta, rows: Record<string, unknown>[], tables: Record<string, string> | undefined, debugSql: SqlQueryFn): Promise<void>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=link-display.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link-display.d.ts","sourceRoot":"","sources":["../../src/link-display.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAK5C,KAAK,UAAU,GAAG,CACjB,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAA;CAAE,KACvC,OAAO,CAAC;IAAE,IAAI,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;CAAE,CAAC,CAAA;AA6C1D;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC5C,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC1C,QAAQ,EAAE,UAAU,GAClB,OAAO,CAAC,IAAI,CAAC,CAqCf"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { camelToSnake, flattenFields, getDisplayField, getRecordIdField, linkDisplayFieldname } from '@stonecrop/schema';
|
|
2
|
+
import { getMeta } from './registry/doctypes';
|
|
3
|
+
import { resolveTableName } from './tables';
|
|
4
|
+
/** Normalize a scalar FK cell value to a non-empty string id, or skip objects/null. */
|
|
5
|
+
function fkIdKey(value) {
|
|
6
|
+
if (value == null || typeof value === 'object')
|
|
7
|
+
return undefined;
|
|
8
|
+
if (typeof value === 'string')
|
|
9
|
+
return value === '' ? undefined : value;
|
|
10
|
+
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') {
|
|
11
|
+
return String(value);
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
function collectLinkDisplaySpecs(meta, tables) {
|
|
16
|
+
const specs = [];
|
|
17
|
+
for (const field of flattenFields(meta.fields)) {
|
|
18
|
+
if (field.kind !== 'field' || !field.doctype)
|
|
19
|
+
continue;
|
|
20
|
+
const targetMeta = getMeta(field.doctype);
|
|
21
|
+
if (!targetMeta)
|
|
22
|
+
continue;
|
|
23
|
+
// `getDisplayField` rather than a lookup written here: it is the same call `DoctypeMeta`
|
|
24
|
+
// makes at the load gate, so a nomination that parsed is one this can build a SELECT from.
|
|
25
|
+
// A hand-rolled scan here admitted `computed` fields, whose column does not exist.
|
|
26
|
+
const displayField = getDisplayField(targetMeta.fields, targetMeta.displayField);
|
|
27
|
+
if (!displayField)
|
|
28
|
+
continue;
|
|
29
|
+
specs.push({
|
|
30
|
+
fieldname: field.fieldname,
|
|
31
|
+
displayField: displayField.fieldname,
|
|
32
|
+
targetPkFieldname: getRecordIdField(targetMeta.fields),
|
|
33
|
+
targetTable: resolveTableName(targetMeta.name, tables),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return specs;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Add `fieldname__display` alongside each inline foreign-key field when the target doctype
|
|
40
|
+
* declares a `displayField`. Scalar FK values only — expanded relations are skipped.
|
|
41
|
+
*
|
|
42
|
+
* Takes every row at once and issues one lookup per FK field, not per row. Callers holding a batch
|
|
43
|
+
* must pass the whole batch: called per row inside a loader's own loop it reinstates the N+1 the
|
|
44
|
+
* loader exists to prevent, and does so invisibly, since the result is identical either way.
|
|
45
|
+
*/
|
|
46
|
+
export async function enrichLinkDisplayFields(pgClient, meta, rows, tables, debugSql) {
|
|
47
|
+
const specs = collectLinkDisplaySpecs(meta, tables);
|
|
48
|
+
if (specs.length === 0 || rows.length === 0)
|
|
49
|
+
return;
|
|
50
|
+
await Promise.all(specs.map(async (spec) => {
|
|
51
|
+
const ids = new Set();
|
|
52
|
+
for (const row of rows) {
|
|
53
|
+
const id = fkIdKey(row[spec.fieldname]);
|
|
54
|
+
if (id !== undefined)
|
|
55
|
+
ids.add(id);
|
|
56
|
+
}
|
|
57
|
+
if (ids.size === 0)
|
|
58
|
+
return;
|
|
59
|
+
const pkColumn = camelToSnake(spec.targetPkFieldname);
|
|
60
|
+
const displayColumn = camelToSnake(spec.displayField);
|
|
61
|
+
const displayAlias = displayColumn !== spec.displayField ? `"${displayColumn}" AS "${spec.displayField}"` : `"${spec.displayField}"`;
|
|
62
|
+
const { rows: displayRows } = await debugSql(pgClient, {
|
|
63
|
+
text: `SELECT "${pkColumn}" AS "${spec.targetPkFieldname}", ${displayAlias} FROM ${spec.targetTable} WHERE "${pkColumn}"::text = ANY($1::text[])`,
|
|
64
|
+
values: [Array.from(ids)],
|
|
65
|
+
});
|
|
66
|
+
const displayById = new Map();
|
|
67
|
+
for (const displayRow of displayRows) {
|
|
68
|
+
displayById.set(String(displayRow[spec.targetPkFieldname]), displayRow[spec.displayField]);
|
|
69
|
+
}
|
|
70
|
+
for (const row of rows) {
|
|
71
|
+
const id = fkIdKey(row[spec.fieldname]);
|
|
72
|
+
if (id === undefined)
|
|
73
|
+
continue;
|
|
74
|
+
const displayValue = displayById.get(id);
|
|
75
|
+
if (displayValue == null || displayValue === '')
|
|
76
|
+
continue;
|
|
77
|
+
row[linkDisplayFieldname(spec.fieldname)] = displayValue;
|
|
78
|
+
}
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
@@ -163,4 +163,10 @@ export declare const createStonecropPlugin: (options?: StonecropPluginOptions) =
|
|
|
163
163
|
* Exported for unit testing (not re-exported from the package index).
|
|
164
164
|
*/
|
|
165
165
|
export declare function getSqlColumns(meta: DoctypeMeta): string;
|
|
166
|
+
/**
|
|
167
|
+
* Resolve the PostgreSQL FROM clause target for a doctype.
|
|
168
|
+
* Uses the `tables` override map first; falls back to camelToSnake(name).
|
|
169
|
+
* Schema-qualified names (e.g. "orpin.plan") are emitted as "schema"."table".
|
|
170
|
+
* Values must be bare identifiers or schema.table pairs — not SQL fragments.
|
|
171
|
+
*/
|
|
166
172
|
//# sourceMappingURL=postgraphile.d.ts.map
|
|
@@ -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;
|
|
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;;;;;OAKG;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,MA8qB3F,CAAA;AA0BD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAQvD;AA6HD;;;;;GAKG"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { camelToSnake, getRecordIdField,
|
|
1
|
+
import { camelToSnake, getRecordIdField, resolveLinkRenderMode } 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';
|
|
5
5
|
import { columnBackedFields, flattenFields } from '../fields';
|
|
6
|
+
import { enrichLinkDisplayFields } from '../link-display';
|
|
7
|
+
import { resolveTableName } from '../tables';
|
|
6
8
|
import { getFetchHandler } from '../registry/fetchHandlers';
|
|
7
9
|
import { getMeta, getAllMeta, validateReferences } from '../registry/doctypes';
|
|
8
10
|
import { applyGuardedTransition } from '../dispatch/transition';
|
|
@@ -169,6 +171,11 @@ export const createStonecropPlugin = (options = {}) => {
|
|
|
169
171
|
`matched ${rowByPk.size} distinct values, so a lookup cannot say which record it means. ` +
|
|
170
172
|
`Declare a field that uniquely identifies a record, or add a unique constraint.`);
|
|
171
173
|
}
|
|
174
|
+
// Collected across the batch so the display lookup runs once for all of them.
|
|
175
|
+
// Called per row inside this loop it issued one query per record per link field,
|
|
176
|
+
// which is the N+1 this batched loader exists to avoid — and silently, since the
|
|
177
|
+
// enriched rows come out identical either way.
|
|
178
|
+
const enrichedRows = [];
|
|
172
179
|
for (const i of indices) {
|
|
173
180
|
const specId = String(specs[i].id);
|
|
174
181
|
const row = rowByPk.get(specId);
|
|
@@ -177,6 +184,7 @@ export const createStonecropPlugin = (options = {}) => {
|
|
|
177
184
|
continue;
|
|
178
185
|
}
|
|
179
186
|
const rowData = { ...row };
|
|
187
|
+
enrichedRows.push(rowData);
|
|
180
188
|
// Per record, not per doctype: two records of one doctype can differ in whether
|
|
181
189
|
// a relation overflowed, and a shared list would report the wrong one truncated.
|
|
182
190
|
const truncatedLinks = [];
|
|
@@ -307,6 +315,10 @@ export const createStonecropPlugin = (options = {}) => {
|
|
|
307
315
|
truncatedLinks: truncatedLinks.length ? truncatedLinks : undefined,
|
|
308
316
|
};
|
|
309
317
|
}
|
|
318
|
+
// After the expansion loop, not before it: a link that expanded has replaced its
|
|
319
|
+
// scalar FK with an object, and enrichment skips those. Running first stamped a
|
|
320
|
+
// display value beside a relation that no longer had an id to display.
|
|
321
|
+
await enrichLinkDisplayFields(pgClient, meta, enrichedRows, options.tables, debugSql);
|
|
310
322
|
}
|
|
311
323
|
return results;
|
|
312
324
|
});
|
|
@@ -396,7 +408,8 @@ export const createStonecropPlugin = (options = {}) => {
|
|
|
396
408
|
// a capped page distinguishable from a complete table; trim it before anything
|
|
397
409
|
// downstream can mistake it for a record.
|
|
398
410
|
const hasMore = effectiveLimit != null && rows.length > effectiveLimit;
|
|
399
|
-
const data = hasMore ? rows.slice(0, effectiveLimit ?? rows.length) : rows;
|
|
411
|
+
const data = [...(hasMore ? rows.slice(0, effectiveLimit ?? rows.length) : rows)];
|
|
412
|
+
await enrichLinkDisplayFields(pgClient, meta, data, options.tables, debugSql);
|
|
400
413
|
// Total matching the filters, independent of LIMIT/OFFSET, and opt-in.
|
|
401
414
|
//
|
|
402
415
|
// Explicitly requested rather than inferred from whether `count` was selected:
|
|
@@ -815,11 +828,3 @@ function unresolvableIdentityError(doctype) {
|
|
|
815
828
|
* Schema-qualified names (e.g. "orpin.plan") are emitted as "schema"."table".
|
|
816
829
|
* Values must be bare identifiers or schema.table pairs — not SQL fragments.
|
|
817
830
|
*/
|
|
818
|
-
function resolveTableName(name, tables) {
|
|
819
|
-
const target = tables?.[name] ?? pascalToSnake(name);
|
|
820
|
-
const dotIndex = target.indexOf('.');
|
|
821
|
-
if (dotIndex > 0) {
|
|
822
|
-
return `"${target.slice(0, dotIndex)}"."${target.slice(dotIndex + 1)}"`;
|
|
823
|
-
}
|
|
824
|
-
return `"${target}"`;
|
|
825
|
-
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The quoted SQL table a doctype reads from: the `tables` override when the adapter supplies one,
|
|
3
|
+
* otherwise the doctype name snake-cased.
|
|
4
|
+
*
|
|
5
|
+
* The one definition of that mapping. It lives in its own module rather than beside either caller
|
|
6
|
+
* because the plugin imports the link-display enrichment, so the enrichment cannot import back —
|
|
7
|
+
* and the copy it made instead was byte-identical, which is the state a mapping is in right before
|
|
8
|
+
* one side learns about schema-qualified names and the other does not.
|
|
9
|
+
*
|
|
10
|
+
* A dotted override is read as `schema.table` and quoted in two parts, so a table in a non-default
|
|
11
|
+
* Postgres schema survives quoting instead of becoming one identifier containing a dot.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveTableName(name: string, tables?: Record<string, string>): string;
|
|
14
|
+
//# sourceMappingURL=tables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../src/tables.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAOtF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { pascalToSnake } from '@stonecrop/schema';
|
|
2
|
+
/**
|
|
3
|
+
* The quoted SQL table a doctype reads from: the `tables` override when the adapter supplies one,
|
|
4
|
+
* otherwise the doctype name snake-cased.
|
|
5
|
+
*
|
|
6
|
+
* The one definition of that mapping. It lives in its own module rather than beside either caller
|
|
7
|
+
* because the plugin imports the link-display enrichment, so the enrichment cannot import back —
|
|
8
|
+
* and the copy it made instead was byte-identical, which is the state a mapping is in right before
|
|
9
|
+
* one side learns about schema-qualified names and the other does not.
|
|
10
|
+
*
|
|
11
|
+
* A dotted override is read as `schema.table` and quoted in two parts, so a table in a non-default
|
|
12
|
+
* Postgres schema survives quoting instead of becoming one identifier containing a dot.
|
|
13
|
+
*/
|
|
14
|
+
export function resolveTableName(name, tables) {
|
|
15
|
+
const target = tables?.[name] ?? pascalToSnake(name);
|
|
16
|
+
const dotIndex = target.indexOf('.');
|
|
17
|
+
if (dotIndex > 0) {
|
|
18
|
+
return `"${target.slice(0, dotIndex)}"."${target.slice(dotIndex + 1)}"`;
|
|
19
|
+
}
|
|
20
|
+
return `"${target}"`;
|
|
21
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeDefs.d.ts","sourceRoot":"","sources":["../../src/typeDefs.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"typeDefs.d.ts","sourceRoot":"","sources":["../../src/typeDefs.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,QAAQ,gCA8GpB,CAAA"}
|
package/dist/src/typeDefs.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/graphql-middleware",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "GraphQL middleware for PostGraphile and Stonecrop schema",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"graphql": "^16.14.0",
|
|
24
24
|
"pluralize": "^8.0.0",
|
|
25
25
|
"postgraphile": "^5.0.3",
|
|
26
|
-
"@stonecrop/schema": "0.
|
|
26
|
+
"@stonecrop/schema": "0.19.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@electric-sql/pglite": "^0.4.5",
|