@stonecrop/graphql-middleware 0.13.9 → 0.13.10
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.
|
@@ -8,19 +8,45 @@ import { ValidationError } from '@stonecrop/schema';
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Context passed to action handlers.
|
|
11
|
+
*
|
|
12
|
+
* The open index signature is the extension point for injecting an
|
|
13
|
+
* application-owned data access layer (see ADR 0003) — in a PostGraphile
|
|
14
|
+
* setup that slot is {@link ActionContext.pgClient}; custom backends inject
|
|
15
|
+
* their own (e.g. an in-memory executor).
|
|
16
|
+
*
|
|
11
17
|
* @public
|
|
12
18
|
*/
|
|
13
19
|
export declare interface ActionContext {
|
|
14
20
|
/** Doctype metadata for the action being executed */
|
|
15
21
|
doctype: DoctypeMeta;
|
|
16
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Active database client — available when the action is dispatched via stonecropAction.
|
|
24
|
+
*
|
|
25
|
+
* Rows returned by raw `pgClient.query()` carry **snake_case column names**,
|
|
26
|
+
* not the camelCase fieldnames the client expects (see ADR 0004 — the
|
|
27
|
+
* middleware's own read paths alias columns at the SQL layer, e.g.
|
|
28
|
+
* `"display_name" AS "displayName"`). Handlers querying with `pgClient`
|
|
29
|
+
* own the same conversion for their return values — see {@link ActionHandler}.
|
|
30
|
+
*/
|
|
17
31
|
pgClient?: PgClient;
|
|
18
32
|
/** Additional context properties */
|
|
19
33
|
[key: string]: unknown;
|
|
20
34
|
}
|
|
21
35
|
|
|
22
36
|
/**
|
|
23
|
-
* Action handler function signature
|
|
37
|
+
* Action handler function signature.
|
|
38
|
+
*
|
|
39
|
+
* The resolved value is passed through verbatim as `ActionResult.data` —
|
|
40
|
+
* the middleware applies no transformation. Return **API-layer data**: plain
|
|
41
|
+
* objects keyed by camelCase fieldnames, matching what `stonecropRecord`
|
|
42
|
+
* returns (see ADR 0004).
|
|
43
|
+
*
|
|
44
|
+
* When reading from the database via `context.pgClient`, either alias columns
|
|
45
|
+
* in the SQL (`SELECT display_name AS "displayName" ...`, as the middleware's
|
|
46
|
+
* own queries do) or convert row keys with `snakeToCamel` from
|
|
47
|
+
* `@stonecrop/schema` before returning. Returning raw query rows leaks
|
|
48
|
+
* snake_case column names to the client.
|
|
49
|
+
*
|
|
24
50
|
* @public
|
|
25
51
|
*/
|
|
26
52
|
export declare type ActionHandler = (args: unknown[], context: ActionContext) => Promise<unknown>;
|
|
@@ -2,18 +2,44 @@ import type { PgClient } from '@dataplan/pg';
|
|
|
2
2
|
import type { DoctypeMeta } from '@stonecrop/schema';
|
|
3
3
|
/**
|
|
4
4
|
* Context passed to action handlers.
|
|
5
|
+
*
|
|
6
|
+
* The open index signature is the extension point for injecting an
|
|
7
|
+
* application-owned data access layer (see ADR 0003) — in a PostGraphile
|
|
8
|
+
* setup that slot is {@link ActionContext.pgClient}; custom backends inject
|
|
9
|
+
* their own (e.g. an in-memory executor).
|
|
10
|
+
*
|
|
5
11
|
* @public
|
|
6
12
|
*/
|
|
7
13
|
export interface ActionContext {
|
|
8
14
|
/** Doctype metadata for the action being executed */
|
|
9
15
|
doctype: DoctypeMeta;
|
|
10
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Active database client — available when the action is dispatched via stonecropAction.
|
|
18
|
+
*
|
|
19
|
+
* Rows returned by raw `pgClient.query()` carry **snake_case column names**,
|
|
20
|
+
* not the camelCase fieldnames the client expects (see ADR 0004 — the
|
|
21
|
+
* middleware's own read paths alias columns at the SQL layer, e.g.
|
|
22
|
+
* `"display_name" AS "displayName"`). Handlers querying with `pgClient`
|
|
23
|
+
* own the same conversion for their return values — see {@link ActionHandler}.
|
|
24
|
+
*/
|
|
11
25
|
pgClient?: PgClient;
|
|
12
26
|
/** Additional context properties */
|
|
13
27
|
[key: string]: unknown;
|
|
14
28
|
}
|
|
15
29
|
/**
|
|
16
|
-
* Action handler function signature
|
|
30
|
+
* Action handler function signature.
|
|
31
|
+
*
|
|
32
|
+
* The resolved value is passed through verbatim as `ActionResult.data` —
|
|
33
|
+
* the middleware applies no transformation. Return **API-layer data**: plain
|
|
34
|
+
* objects keyed by camelCase fieldnames, matching what `stonecropRecord`
|
|
35
|
+
* returns (see ADR 0004).
|
|
36
|
+
*
|
|
37
|
+
* When reading from the database via `context.pgClient`, either alias columns
|
|
38
|
+
* in the SQL (`SELECT display_name AS "displayName" ...`, as the middleware's
|
|
39
|
+
* own queries do) or convert row keys with `snakeToCamel` from
|
|
40
|
+
* `@stonecrop/schema` before returning. Returning raw query rows leaks
|
|
41
|
+
* snake_case column names to the client.
|
|
42
|
+
*
|
|
17
43
|
* @public
|
|
18
44
|
*/
|
|
19
45
|
export type ActionHandler = (args: unknown[], context: ActionContext) => Promise<unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa;IAC7B,qDAAqD;IACrD,OAAO,EAAE,WAAW,CAAA;IACpB;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,oCAAoC;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACtB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/graphql-middleware",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/graphql-middleware.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"graphql": "^16.14.0",
|
|
19
19
|
"pluralize": "^8.0.0",
|
|
20
20
|
"postgraphile": "^5.0.3",
|
|
21
|
-
"@stonecrop/schema": "0.13.
|
|
21
|
+
"@stonecrop/schema": "0.13.10"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@electric-sql/pglite": "^0.4.5",
|