@stonecrop/graphql-middleware 0.11.1 → 0.11.3
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 +59 -63
- package/dist/graphql-middleware.d.ts +167 -0
- package/dist/index.js +426 -223
- package/dist/index.js.map +1 -1
- package/dist/plugin/postgraphile.js +221 -18
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/plugin/postgraphile.d.ts +56 -16
- package/dist/src/plugin/postgraphile.d.ts.map +1 -1
- package/dist/src/typeDefs.d.ts +7 -0
- package/dist/src/typeDefs.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +1 -0
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/query.d.ts +132 -0
- package/dist/src/types/query.d.ts.map +1 -0
- package/dist/typeDefs.js +79 -0
- package/dist/types/query.js +3 -0
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DoctypeMeta } from '@stonecrop/schema';
|
|
2
2
|
import { GraphileConfig } from 'postgraphile/graphile-build';
|
|
3
|
-
import type { GraphQLExecutor } from '../types';
|
|
3
|
+
import type { GraphQLExecutor, ReverseConnectionParams, BuildRecordQueryOptions, BuildListQueryArgs, MergeNestedResultsParams, ExtractSingleResultParams, ExtractListResultParams } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* Inflection callbacks for mapping table names to GraphQL query field names.
|
|
6
6
|
* Override these when using a non-Amber inflection preset (e.g., V4, SimplifyInflection).
|
|
@@ -38,6 +38,33 @@ export interface StonecropInflectionConfig {
|
|
|
38
38
|
* @example Integer PK: "sales_orders" → "Int!"
|
|
39
39
|
*/
|
|
40
40
|
recordArgType?: (tableName: string) => string;
|
|
41
|
+
/**
|
|
42
|
+
* Derive the GraphQL connection field name for a reverse-FK link.
|
|
43
|
+
* PostGraphile convention: `{targetPlural}By{FkColumnPascal}Id`
|
|
44
|
+
* - When backlink is provided: FK column is derived from the backlink field
|
|
45
|
+
* - When backlink is absent: FK column is derived from the parent doctype
|
|
46
|
+
* @example Recipe → RecipeTasksByRecipeId
|
|
47
|
+
*/
|
|
48
|
+
reverseConnectionName?: (params: {
|
|
49
|
+
/** Parent doctype slug */
|
|
50
|
+
doctype: string;
|
|
51
|
+
/** Link key on the parent */
|
|
52
|
+
linkName: string;
|
|
53
|
+
/** Link field on the target that points back to the parent (optional) */
|
|
54
|
+
backlink?: string;
|
|
55
|
+
/** Target doctype slug */
|
|
56
|
+
target: string;
|
|
57
|
+
}) => string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Options for stonecropRecord queries
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export interface StonecropRecordOptions {
|
|
64
|
+
/** Include nested/related records */
|
|
65
|
+
includeNested?: boolean | string[];
|
|
66
|
+
/** Maximum nesting depth */
|
|
67
|
+
maxDepth?: number;
|
|
41
68
|
}
|
|
42
69
|
/**
|
|
43
70
|
* Options for creating a Stonecrop PostGraphile plugin
|
|
@@ -90,6 +117,19 @@ declare function defaultRecordArgName(_tableName: string): string;
|
|
|
90
117
|
* @public
|
|
91
118
|
*/
|
|
92
119
|
declare function defaultRecordArgType(_tableName: string): string;
|
|
120
|
+
/**
|
|
121
|
+
* Default reverse connection name: derives PostGraphile's connection field convention.
|
|
122
|
+
* PostGraphile convention: `{targetPlural}By{FkColumnPascal}Id`
|
|
123
|
+
* - When backlink is defined: FK column is derived from the backlink field name
|
|
124
|
+
* - When backlink is absent: FK column is derived from the parent doctype's table name
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
declare function defaultReverseConnectionName(params: {
|
|
128
|
+
doctype: string;
|
|
129
|
+
linkName: string;
|
|
130
|
+
backlink?: string;
|
|
131
|
+
target: string;
|
|
132
|
+
}): string;
|
|
93
133
|
/**
|
|
94
134
|
* Fieldtypes that map to GraphQL object/connection types and require sub-selections.
|
|
95
135
|
* These fields are excluded from generated query field selections.
|
|
@@ -104,13 +144,10 @@ declare const RELATION_FIELDTYPES: Set<string>;
|
|
|
104
144
|
declare function queryableFieldNames(meta: DoctypeMeta): string;
|
|
105
145
|
/**
|
|
106
146
|
* Build a GraphQL query to fetch a single record by ID.
|
|
107
|
-
*
|
|
108
|
-
* The PK argument name and type are configurable via `StonecropInflectionConfig.recordArgName`
|
|
109
|
-
* and `StonecropInflectionConfig.recordArgType` to match the target schema's conventions
|
|
110
|
-
* (e.g. `rowId: UUID!` for PostGraphile Amber with row_id columns).
|
|
147
|
+
* When includeNested is set, recursively includes descendant link sub-selections.
|
|
111
148
|
* @public
|
|
112
149
|
*/
|
|
113
|
-
declare function buildRecordQuery(meta: DoctypeMeta, recordFieldName: (t: string) => string, recordArgName: (t: string) => string, recordArgType: (t: string) => string): string;
|
|
150
|
+
declare function buildRecordQuery(meta: DoctypeMeta, recordFieldName: (t: string) => string, recordArgName: (t: string) => string, recordArgType: (t: string) => string, getMeta: (slug: string) => DoctypeMeta | undefined, options?: BuildRecordQueryOptions, reverseConnectionNameFn?: (params: ReverseConnectionParams) => string): string;
|
|
114
151
|
/**
|
|
115
152
|
* Build a GraphQL connection query to fetch a list of records.
|
|
116
153
|
* Only declares variables ($limit, $offset, $orderBy) that are actually used in the query,
|
|
@@ -118,21 +155,24 @@ declare function buildRecordQuery(meta: DoctypeMeta, recordFieldName: (t: string
|
|
|
118
155
|
* Excludes Link and Doctype relation fields from the selection set.
|
|
119
156
|
* @public
|
|
120
157
|
*/
|
|
121
|
-
declare function buildListQuery(meta: DoctypeMeta, args:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
158
|
+
declare function buildListQuery(meta: DoctypeMeta, args: BuildListQueryArgs, connectionFieldName: (t: string) => string, orderByTypeName: (t: string) => string): string;
|
|
159
|
+
/**
|
|
160
|
+
* Merge nested connection results into flat arrays.
|
|
161
|
+
* For `noneOrMany`/`atLeastOne` links, the query returns `{ nodes: [...] }`.
|
|
162
|
+
* This flattens them to just `[]` for easier consumption.
|
|
163
|
+
* @public
|
|
164
|
+
*/
|
|
165
|
+
declare function mergeNestedResults(params: MergeNestedResultsParams): Record<string, unknown>;
|
|
126
166
|
/**
|
|
127
167
|
* Extract a single record from a PostGraphile query result using the record field name.
|
|
128
|
-
* @
|
|
168
|
+
* @public
|
|
129
169
|
*/
|
|
130
|
-
declare function extractSingleResult(
|
|
170
|
+
declare function extractSingleResult(params: ExtractSingleResultParams): unknown;
|
|
131
171
|
/**
|
|
132
172
|
* Extract the list of nodes from a PostGraphile connection query result.
|
|
133
173
|
* Returns an empty array if the connection field is absent.
|
|
134
|
-
* @
|
|
174
|
+
* @public
|
|
135
175
|
*/
|
|
136
|
-
declare function extractListResult(
|
|
137
|
-
export { defaultRecordFieldName, defaultConnectionFieldName, defaultOrderByTypeName, defaultRecordArgName, defaultRecordArgType, buildRecordQuery, buildListQuery, queryableFieldNames, RELATION_FIELDTYPES, extractSingleResult, extractListResult, };
|
|
176
|
+
declare function extractListResult(params: ExtractListResultParams): unknown[];
|
|
177
|
+
export { defaultRecordFieldName, defaultConnectionFieldName, defaultOrderByTypeName, defaultRecordArgName, defaultRecordArgType, defaultReverseConnectionName, buildRecordQuery, buildListQuery, queryableFieldNames, RELATION_FIELDTYPES, extractSingleResult, extractListResult, mergeNestedResults, };
|
|
138
178
|
//# 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,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"postgraphile.d.ts","sourceRoot":"","sources":["../../../src/plugin/postgraphile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAyC,MAAM,mBAAmB,CAAA;AAG3F,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAM5D,OAAO,KAAK,EAEX,eAAe,EACf,uBAAu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B,mBAAmB,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,EAC1C,eAAe,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GACpC,MAAM,CAgCR;AAED;;;;;GAKG;AACH,iBAAS,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAkCrF;AAED;;;GAGG;AACH,iBAAS,mBAAmB,CAAC,MAAM,EAAE,yBAAyB,GAAG,OAAO,CAIvE;AAED;;;;GAIG;AACH,iBAAS,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,EAAE,CAOrE;AAMD,OAAO,EACN,sBAAsB,EACtB,0BAA0B,EAC1B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,GAClB,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GraphQL type definitions for Stonecrop's middleware API.
|
|
3
|
+
* Includes stonecropMeta, stonecropRecord, stonecropRecords, stonecropAction, and related types.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare const typeDefs: import("graphql").DocumentNode;
|
|
7
|
+
//# sourceMappingURL=typeDefs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeDefs.d.ts","sourceRoot":"","sources":["../../src/typeDefs.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,QAAQ,gCAwEpB,CAAA"}
|
|
@@ -26,4 +26,5 @@ export interface ActionContext {
|
|
|
26
26
|
* @public
|
|
27
27
|
*/
|
|
28
28
|
export type ActionHandler = (args: unknown[], context: ActionContext) => Promise<unknown>;
|
|
29
|
+
export type { ReverseConnectionParams, BuildRecordQueryOptions, BuildRecordQueryParams, BuildNestedSelectionsParams, BuildListQueryArgs, BuildListQueryParams, MergeNestedResultsParams, ExtractSingleResultParams, ExtractListResultParams, } from './query';
|
|
29
30
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,8BAA8B;IAC9B,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;IAClF,iCAAiC;IACjC,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;CACtF;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B,qDAAqD;IACrD,OAAO,EAAE,WAAW,CAAA;IACpB,uEAAuE;IACvE,QAAQ,EAAE,eAAe,CAAA;IACzB,oCAAoC;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACtB;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,8BAA8B;IAC9B,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;IAClF,iCAAiC;IACjC,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;CACtF;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B,qDAAqD;IACrD,OAAO,EAAE,WAAW,CAAA;IACpB,uEAAuE;IACvE,QAAQ,EAAE,eAAe,CAAA;IACzB,oCAAoC;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACtB;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAGzF,YAAY,EACX,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,2BAA2B,EAC3B,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,EACzB,uBAAuB,GACvB,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { DoctypeMeta, LinkDeclaration } from '@stonecrop/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for reverse connection name inflection
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface ReverseConnectionParams {
|
|
7
|
+
/** Parent doctype slug */
|
|
8
|
+
doctype: string;
|
|
9
|
+
/** Link key on the parent */
|
|
10
|
+
linkName: string;
|
|
11
|
+
/** Link field on the target that points back to the parent (optional) */
|
|
12
|
+
backlink?: string;
|
|
13
|
+
/** Target doctype slug */
|
|
14
|
+
target: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Options for buildRecordQuery nested selection building
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export interface BuildRecordQueryOptions {
|
|
21
|
+
/** Include nested/related records */
|
|
22
|
+
includeNested?: boolean | string[];
|
|
23
|
+
/** Maximum nesting depth */
|
|
24
|
+
maxDepth?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parameters for buildRecordQuery
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export interface BuildRecordQueryParams {
|
|
31
|
+
/** Doctype metadata */
|
|
32
|
+
meta: DoctypeMeta;
|
|
33
|
+
/** Function to derive the record field name from a table name */
|
|
34
|
+
recordFieldName: (tableName: string) => string;
|
|
35
|
+
/** Function to derive the record argument name from a table name */
|
|
36
|
+
recordArgName: (tableName: string) => string;
|
|
37
|
+
/** Function to derive the record argument type from a table name */
|
|
38
|
+
recordArgType: (tableName: string) => string;
|
|
39
|
+
/** Lookup function to get doctype metadata by slug */
|
|
40
|
+
getMeta: (slug: string) => DoctypeMeta | undefined;
|
|
41
|
+
/** Options for nested query building */
|
|
42
|
+
options?: BuildRecordQueryOptions;
|
|
43
|
+
/** Function to derive reverse connection field names */
|
|
44
|
+
reverseConnectionNameFn?: (params: ReverseConnectionParams) => string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Parameters for buildNestedSelections
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
export interface BuildNestedSelectionsParams {
|
|
51
|
+
/** Link declarations from the parent doctype */
|
|
52
|
+
links: Record<string, LinkDeclaration>;
|
|
53
|
+
/** Parent doctype metadata */
|
|
54
|
+
meta: DoctypeMeta;
|
|
55
|
+
/** Set of link names to include, or null for all */
|
|
56
|
+
includeSet: Set<string> | null;
|
|
57
|
+
/** Lookup function to get doctype metadata by slug */
|
|
58
|
+
getMeta: (slug: string) => DoctypeMeta | undefined;
|
|
59
|
+
/** Set of already-seen doctype slugs to prevent circular references */
|
|
60
|
+
seen: Set<string>;
|
|
61
|
+
/** Current recursion depth */
|
|
62
|
+
depth: number;
|
|
63
|
+
/** Maximum recursion depth */
|
|
64
|
+
maxDepth?: number;
|
|
65
|
+
/** Function to derive reverse connection field names */
|
|
66
|
+
reverseConnectionNameFn?: (params: ReverseConnectionParams) => string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Arguments for buildListQuery
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
export interface BuildListQueryArgs {
|
|
73
|
+
/** Maximum number of records to return */
|
|
74
|
+
limit?: number;
|
|
75
|
+
/** Number of records to skip */
|
|
76
|
+
offset?: number;
|
|
77
|
+
/** OrderBy specification */
|
|
78
|
+
orderBy?: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Parameters for buildListQuery
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export interface BuildListQueryParams {
|
|
85
|
+
/** Doctype metadata */
|
|
86
|
+
meta: DoctypeMeta;
|
|
87
|
+
/** Query arguments */
|
|
88
|
+
args: BuildListQueryArgs;
|
|
89
|
+
/** Function to derive the connection field name from a table name */
|
|
90
|
+
connectionFieldName: (tableName: string) => string;
|
|
91
|
+
/** Function to derive the OrderBy type name from a table name */
|
|
92
|
+
orderByTypeName: (tableName: string) => string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Parameters for mergeNestedResults
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export interface MergeNestedResultsParams {
|
|
99
|
+
/** The record object with nested connection data */
|
|
100
|
+
record: Record<string, unknown>;
|
|
101
|
+
/** Doctype metadata */
|
|
102
|
+
meta: DoctypeMeta;
|
|
103
|
+
/** Lookup function to get doctype metadata by slug */
|
|
104
|
+
getMeta: (slug: string) => DoctypeMeta | undefined;
|
|
105
|
+
/** Function to derive the reverse connection field name from link params */
|
|
106
|
+
reverseConnectionNameFn?: (params: ReverseConnectionParams) => string;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Parameters for extractSingleResult
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
112
|
+
export interface ExtractSingleResultParams {
|
|
113
|
+
/** The raw query result */
|
|
114
|
+
result: unknown;
|
|
115
|
+
/** Doctype metadata */
|
|
116
|
+
meta: DoctypeMeta;
|
|
117
|
+
/** Function to derive the record field name from a table name */
|
|
118
|
+
recordFieldName: (tableName: string) => string;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Parameters for extractListResult
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
export interface ExtractListResultParams {
|
|
125
|
+
/** The raw query result */
|
|
126
|
+
result: unknown;
|
|
127
|
+
/** Doctype metadata */
|
|
128
|
+
meta: DoctypeMeta;
|
|
129
|
+
/** Function to derive the connection field name from a table name */
|
|
130
|
+
connectionFieldName: (tableName: string) => string;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/types/query.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAErE;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACvC,0BAA0B;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,yEAAyE;IACzE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,0BAA0B;IAC1B,MAAM,EAAE,MAAM,CAAA;CACd;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACvC,qCAAqC;IACrC,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;IAClC,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACtC,uBAAuB;IACvB,IAAI,EAAE,WAAW,CAAA;IACjB,iE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;AACH,MAAM,WAAW,oBAAoB;IACpC,uBAAuB;IACvB,IAAI,EAAE,WAAW,CAAA;IACjB,sBAAsB;IACtB,IAAI,EAAE,kBAAkB,CAAA;IACxB,qEAAqE;IACrE,mBAAmB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;IAClD,iEAAiE;IACjE,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;CAC9C;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACxC,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,uBAAuB;IACvB,IAAI,EAAE,WAAW,CAAA;IACjB,sDAAsD;IACtD,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,WAAW,GAAG,SAAS,CAAA;IAClD,4EAA4E;IAC5E,uBAAuB,CAAC,EAAE,CAAC,MAAM,EAAE,uBAAuB,KAAK,MAAM,CAAA;CACrE;AAED;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACzC,2BAA2B;IAC3B,MAAM,EAAE,OAAO,CAAA;IACf,uBAAuB;IACvB,IAAI,EAAE,WAAW,CAAA;IACjB,iEAAiE;IACjE,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;CAC9C;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACvC,2BAA2B;IAC3B,MAAM,EAAE,OAAO,CAAA;IACf,uBAAuB;IACvB,IAAI,EAAE,WAAW,CAAA;IACjB,qEAAqE;IACrE,mBAAmB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;CAClD"}
|
package/dist/typeDefs.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { gql } from 'postgraphile/utils';
|
|
2
|
+
/**
|
|
3
|
+
* GraphQL type definitions for Stonecrop's middleware API.
|
|
4
|
+
* Includes stonecropMeta, stonecropRecord, stonecropRecords, stonecropAction, and related types.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export const typeDefs = gql `
|
|
8
|
+
type StonecropFieldMeta {
|
|
9
|
+
fieldname: String!
|
|
10
|
+
fieldtype: String!
|
|
11
|
+
component: String
|
|
12
|
+
label: String
|
|
13
|
+
width: String
|
|
14
|
+
align: String
|
|
15
|
+
required: Boolean
|
|
16
|
+
readOnly: Boolean
|
|
17
|
+
edit: Boolean
|
|
18
|
+
hidden: Boolean
|
|
19
|
+
default: JSON
|
|
20
|
+
options: JSON
|
|
21
|
+
mask: String
|
|
22
|
+
precision: Int
|
|
23
|
+
scale: Int
|
|
24
|
+
mode: String
|
|
25
|
+
validation: JSON
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type StonecropWorkflowAction {
|
|
29
|
+
label: String!
|
|
30
|
+
handler: String!
|
|
31
|
+
requiredFields: [String!]
|
|
32
|
+
allowedStates: [String!]
|
|
33
|
+
confirm: Boolean
|
|
34
|
+
args: JSON
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type StonecropWorkflowMeta {
|
|
38
|
+
states: [String!]
|
|
39
|
+
actions: [StonecropWorkflowAction!]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type StonecropDoctypeMeta {
|
|
43
|
+
name: String!
|
|
44
|
+
slug: String
|
|
45
|
+
tableName: String
|
|
46
|
+
fields: [StonecropFieldMeta!]!
|
|
47
|
+
workflow: StonecropWorkflowMeta
|
|
48
|
+
inherits: String
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type StonecropRecordResult {
|
|
52
|
+
data: JSON
|
|
53
|
+
doctype: String!
|
|
54
|
+
unknownLinks: [String!]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type StonecropRecordsResult {
|
|
58
|
+
data: [JSON!]!
|
|
59
|
+
doctype: String!
|
|
60
|
+
count: Int!
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
type StonecropActionResult {
|
|
64
|
+
success: Boolean!
|
|
65
|
+
data: JSON
|
|
66
|
+
error: String
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
extend type Query {
|
|
70
|
+
stonecropMeta(doctype: String!): StonecropDoctypeMeta
|
|
71
|
+
stonecropAllMeta: [StonecropDoctypeMeta!]!
|
|
72
|
+
stonecropRecord(doctype: String!, id: String!, options: JSON): StonecropRecordResult
|
|
73
|
+
stonecropRecords(doctype: String!, filters: JSON, orderBy: String, limit: Int, offset: Int): StonecropRecordsResult
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
extend type Mutation {
|
|
77
|
+
stonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!
|
|
78
|
+
}
|
|
79
|
+
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/graphql-middleware",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/graphql-middleware.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"graphql": "^16.12.0",
|
|
18
18
|
"pluralize": "^8.0.0",
|
|
19
19
|
"postgraphile": "^5.0.0-rc.7",
|
|
20
|
-
"@stonecrop/schema": "0.11.
|
|
20
|
+
"@stonecrop/schema": "0.11.3"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@rushstack/heft": "^1.2.0",
|