@stonecrop/graphql-middleware 0.8.10 → 0.8.12
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/graphql-middleware.d.ts +23 -753
- package/dist/index.cjs +13 -98
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +228 -438
- package/dist/index.js.map +1 -1
- package/dist/{src/plugin → plugin}/postgraphile.js +49 -13
- package/dist/{src/registry → registry}/doctypes.js +1 -1
- package/dist/src/index.d.ts +2 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/plugin/postgraphile.d.ts +51 -10
- package/dist/src/plugin/postgraphile.d.ts.map +1 -1
- package/dist/src/registry/actions.d.ts.map +1 -1
- package/dist/src/registry/doctypes.d.ts +1 -1
- package/dist/src/registry/doctypes.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +0 -14
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -0
- package/package.json +8 -4
- package/dist/src/client/index.d.ts +0 -75
- package/dist/src/client/index.d.ts.map +0 -1
- package/dist/src/client/index.js +0 -191
- package/dist/src/index.js +0 -24
- package/dist/src/types/index.js +0 -2
- package/dist/tests/query-builders.test.d.ts +0 -2
- package/dist/tests/query-builders.test.d.ts.map +0 -1
- package/dist/tests/query-builders.test.js +0 -178
- package/dist/tests/registry.test.d.ts +0 -2
- package/dist/tests/registry.test.d.ts.map +0 -1
- package/dist/tests/registry.test.js +0 -4
- /package/dist/{src/registry → registry}/actions.js +0 -0
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { DoctypeMeta, RouteContext, GraphQLExecutor } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Options for creating a Stonecrop client
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
export interface StonecropClientOptions {
|
|
7
|
-
/** GraphQL endpoint URL */
|
|
8
|
-
endpoint: string;
|
|
9
|
-
/** Additional HTTP headers to include in requests */
|
|
10
|
-
headers?: Record<string, string>;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Client for interacting with Stonecrop GraphQL API
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
16
|
-
export declare class StonecropClient implements GraphQLExecutor {
|
|
17
|
-
private endpoint;
|
|
18
|
-
private headers;
|
|
19
|
-
private metaCache;
|
|
20
|
-
constructor(options: StonecropClientOptions);
|
|
21
|
-
/**
|
|
22
|
-
* Execute a GraphQL query
|
|
23
|
-
* @param query - GraphQL query string
|
|
24
|
-
* @param variables - Query variables
|
|
25
|
-
*/
|
|
26
|
-
query<T = unknown>(query: string, variables?: Record<string, unknown>): Promise<T>;
|
|
27
|
-
/**
|
|
28
|
-
* Execute a GraphQL mutation
|
|
29
|
-
* @param mutation - GraphQL mutation string
|
|
30
|
-
* @param variables - Mutation variables
|
|
31
|
-
*/
|
|
32
|
-
mutate<T = unknown>(mutation: string, variables?: Record<string, unknown>): Promise<T>;
|
|
33
|
-
/**
|
|
34
|
-
* Get doctype metadata
|
|
35
|
-
* @param context - Route context containing doctype name
|
|
36
|
-
*/
|
|
37
|
-
getMeta(context: RouteContext): Promise<DoctypeMeta | null>;
|
|
38
|
-
/**
|
|
39
|
-
* Get all doctype metadata
|
|
40
|
-
*/
|
|
41
|
-
getAllMeta(): Promise<DoctypeMeta[]>;
|
|
42
|
-
/**
|
|
43
|
-
* Get a single record by ID
|
|
44
|
-
* @param doctype - Doctype metadata
|
|
45
|
-
* @param recordId - Record ID to fetch
|
|
46
|
-
*/
|
|
47
|
-
getRecord(doctype: DoctypeMeta, recordId: string): Promise<Record<string, unknown> | null>;
|
|
48
|
-
/**
|
|
49
|
-
* Get multiple records with optional filtering and pagination
|
|
50
|
-
* @param doctype - Doctype metadata
|
|
51
|
-
* @param options - Query options (filters, orderBy, limit, offset)
|
|
52
|
-
*/
|
|
53
|
-
getRecords(doctype: DoctypeMeta, options?: {
|
|
54
|
-
filters?: Record<string, unknown>;
|
|
55
|
-
orderBy?: string;
|
|
56
|
-
limit?: number;
|
|
57
|
-
offset?: number;
|
|
58
|
-
}): Promise<Record<string, unknown>[]>;
|
|
59
|
-
/**
|
|
60
|
-
* Execute a doctype action
|
|
61
|
-
* @param doctype - Doctype metadata
|
|
62
|
-
* @param action - Action name to execute
|
|
63
|
-
* @param args - Action arguments
|
|
64
|
-
*/
|
|
65
|
-
runAction(doctype: DoctypeMeta, action: string, args?: unknown[]): Promise<{
|
|
66
|
-
success: boolean;
|
|
67
|
-
data: unknown;
|
|
68
|
-
error: string | null;
|
|
69
|
-
}>;
|
|
70
|
-
/**
|
|
71
|
-
* Clear the cached doctype metadata
|
|
72
|
-
*/
|
|
73
|
-
clearMetaCache(): void;
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE1E;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACtC,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAChC;AAED;;;GAGG;AACH,qBAAa,eAAgB,YAAW,eAAe;IACtD,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,SAAS,CAAsC;gBAE3C,OAAO,EAAE,sBAAsB;IAQ3C;;;;OAIG;IACG,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAmBxF;;;;OAIG;IACG,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAI5F;;;OAGG;IACG,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IA0CjE;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAsC1C;;;;OAIG;IACG,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAiBhG;;;;OAIG;IACG,UAAU,CACf,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE;QACT,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACjC,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,MAAM,CAAC,EAAE,MAAM,CAAA;KACf,GACC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAiCrC;;;;;OAKG;IACG,SAAS,CACd,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,OAAO,EAAE,GACd,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IAuBrE;;OAEG;IACH,cAAc,IAAI,IAAI;CAGtB"}
|
package/dist/src/client/index.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client for interacting with Stonecrop GraphQL API
|
|
3
|
-
* @public
|
|
4
|
-
*/
|
|
5
|
-
export class StonecropClient {
|
|
6
|
-
endpoint;
|
|
7
|
-
headers;
|
|
8
|
-
metaCache = new Map();
|
|
9
|
-
constructor(options) {
|
|
10
|
-
this.endpoint = options.endpoint;
|
|
11
|
-
this.headers = {
|
|
12
|
-
'Content-Type': 'application/json',
|
|
13
|
-
...options.headers,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Execute a GraphQL query
|
|
18
|
-
* @param query - GraphQL query string
|
|
19
|
-
* @param variables - Query variables
|
|
20
|
-
*/
|
|
21
|
-
async query(query, variables) {
|
|
22
|
-
const response = await fetch(this.endpoint, {
|
|
23
|
-
method: 'POST',
|
|
24
|
-
headers: this.headers,
|
|
25
|
-
body: JSON.stringify({ query, variables }),
|
|
26
|
-
});
|
|
27
|
-
const json = (await response.json());
|
|
28
|
-
if (json.errors?.length) {
|
|
29
|
-
throw new Error(json.errors[0].message);
|
|
30
|
-
}
|
|
31
|
-
return json.data;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Execute a GraphQL mutation
|
|
35
|
-
* @param mutation - GraphQL mutation string
|
|
36
|
-
* @param variables - Mutation variables
|
|
37
|
-
*/
|
|
38
|
-
async mutate(mutation, variables) {
|
|
39
|
-
return this.query(mutation, variables);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Get doctype metadata
|
|
43
|
-
* @param context - Route context containing doctype name
|
|
44
|
-
*/
|
|
45
|
-
async getMeta(context) {
|
|
46
|
-
const cached = this.metaCache.get(context.doctype);
|
|
47
|
-
if (cached)
|
|
48
|
-
return cached;
|
|
49
|
-
const result = await this.query(`
|
|
50
|
-
query GetMeta($doctype: String!) {
|
|
51
|
-
stonecropMeta(doctype: $doctype) {
|
|
52
|
-
name
|
|
53
|
-
slug
|
|
54
|
-
tableName
|
|
55
|
-
fields {
|
|
56
|
-
fieldname
|
|
57
|
-
fieldtype
|
|
58
|
-
component
|
|
59
|
-
label
|
|
60
|
-
required
|
|
61
|
-
readOnly
|
|
62
|
-
options
|
|
63
|
-
precision
|
|
64
|
-
scale
|
|
65
|
-
}
|
|
66
|
-
workflow {
|
|
67
|
-
states
|
|
68
|
-
actions
|
|
69
|
-
}
|
|
70
|
-
inherits
|
|
71
|
-
listDoctype
|
|
72
|
-
parentDoctype
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
`, { doctype: context.doctype });
|
|
76
|
-
if (result.stonecropMeta) {
|
|
77
|
-
this.metaCache.set(context.doctype, result.stonecropMeta);
|
|
78
|
-
}
|
|
79
|
-
return result.stonecropMeta;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Get all doctype metadata
|
|
83
|
-
*/
|
|
84
|
-
async getAllMeta() {
|
|
85
|
-
const result = await this.query(`
|
|
86
|
-
query GetAllMeta {
|
|
87
|
-
stonecropAllMeta {
|
|
88
|
-
name
|
|
89
|
-
slug
|
|
90
|
-
tableName
|
|
91
|
-
fields {
|
|
92
|
-
fieldname
|
|
93
|
-
fieldtype
|
|
94
|
-
component
|
|
95
|
-
label
|
|
96
|
-
required
|
|
97
|
-
readOnly
|
|
98
|
-
options
|
|
99
|
-
precision
|
|
100
|
-
scale
|
|
101
|
-
}
|
|
102
|
-
workflow {
|
|
103
|
-
states
|
|
104
|
-
actions
|
|
105
|
-
}
|
|
106
|
-
inherits
|
|
107
|
-
listDoctype
|
|
108
|
-
parentDoctype
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
`);
|
|
112
|
-
for (const meta of result.stonecropAllMeta) {
|
|
113
|
-
this.metaCache.set(meta.name, meta);
|
|
114
|
-
}
|
|
115
|
-
return result.stonecropAllMeta;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Get a single record by ID
|
|
119
|
-
* @param doctype - Doctype metadata
|
|
120
|
-
* @param recordId - Record ID to fetch
|
|
121
|
-
*/
|
|
122
|
-
async getRecord(doctype, recordId) {
|
|
123
|
-
const result = await this.query(`
|
|
124
|
-
query GetRecord($doctype: String!, $id: String!) {
|
|
125
|
-
stonecropRecord(doctype: $doctype, id: $id) {
|
|
126
|
-
data
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
`, { doctype: doctype.name, id: recordId });
|
|
130
|
-
return result.stonecropRecord.data;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Get multiple records with optional filtering and pagination
|
|
134
|
-
* @param doctype - Doctype metadata
|
|
135
|
-
* @param options - Query options (filters, orderBy, limit, offset)
|
|
136
|
-
*/
|
|
137
|
-
async getRecords(doctype, options) {
|
|
138
|
-
const result = await this.query(`
|
|
139
|
-
query GetRecords(
|
|
140
|
-
$doctype: String!
|
|
141
|
-
$filters: JSON
|
|
142
|
-
$orderBy: String
|
|
143
|
-
$limit: Int
|
|
144
|
-
$offset: Int
|
|
145
|
-
) {
|
|
146
|
-
stonecropRecords(
|
|
147
|
-
doctype: $doctype
|
|
148
|
-
filters: $filters
|
|
149
|
-
orderBy: $orderBy
|
|
150
|
-
limit: $limit
|
|
151
|
-
offset: $offset
|
|
152
|
-
) {
|
|
153
|
-
data
|
|
154
|
-
count
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
`, {
|
|
158
|
-
doctype: doctype.name,
|
|
159
|
-
...options,
|
|
160
|
-
});
|
|
161
|
-
return result.stonecropRecords.data;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Execute a doctype action
|
|
165
|
-
* @param doctype - Doctype metadata
|
|
166
|
-
* @param action - Action name to execute
|
|
167
|
-
* @param args - Action arguments
|
|
168
|
-
*/
|
|
169
|
-
async runAction(doctype, action, args) {
|
|
170
|
-
const result = await this.query(`
|
|
171
|
-
mutation RunAction($doctype: String!, $action: String!, $args: JSON) {
|
|
172
|
-
stonecropAction(doctype: $doctype, action: $action, args: $args) {
|
|
173
|
-
success
|
|
174
|
-
data
|
|
175
|
-
error
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
`, {
|
|
179
|
-
doctype: doctype.name,
|
|
180
|
-
action,
|
|
181
|
-
args,
|
|
182
|
-
});
|
|
183
|
-
return result.stonecropAction;
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Clear the cached doctype metadata
|
|
187
|
-
*/
|
|
188
|
-
clearMetaCache() {
|
|
189
|
-
this.metaCache.clear();
|
|
190
|
-
}
|
|
191
|
-
}
|
package/dist/src/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// Re-export all schema types from @stonecrop/schema
|
|
2
|
-
export {
|
|
3
|
-
// Field types
|
|
4
|
-
StonecropFieldType, TYPE_MAP, getDefaultComponent,
|
|
5
|
-
// Field schema
|
|
6
|
-
FieldMeta, FieldOptions, FieldValidation,
|
|
7
|
-
// Doctype schema
|
|
8
|
-
DoctypeMeta, WorkflowMeta, ActionDefinition,
|
|
9
|
-
// Validation helpers
|
|
10
|
-
validateField, validateDoctype, parseField, parseDoctype,
|
|
11
|
-
// GraphQL to Doctype conversion
|
|
12
|
-
convertGraphQLSchema, GQL_SCALAR_MAP, WELL_KNOWN_SCALARS, defaultIsEntityType, defaultIsEntityField, classifyFieldType,
|
|
13
|
-
// Naming utilities
|
|
14
|
-
toSlug, toPascalCase, pascalToSnake, snakeToCamel, camelToSnake, snakeToLabel, camelToLabel, } from '@stonecrop/schema';
|
|
15
|
-
// Doctype registry
|
|
16
|
-
export { loadDoctypes, loadDoctypesFromObject, getMeta, getAllMeta, hasMeta, clearRegistry, validateReferences, DoctypeValidationError, } from './registry/doctypes';
|
|
17
|
-
// Action handlers
|
|
18
|
-
export { registerHandler, getHandler, hasHandler, clearHandlers, registerBuiltinHandlers, builtinHandlers, } from './registry/actions';
|
|
19
|
-
// PostGraphile plugin
|
|
20
|
-
export { createStonecropPlugin } from './plugin/postgraphile';
|
|
21
|
-
// Query builders and inflection helpers (exported for testing and advanced usage)
|
|
22
|
-
export { defaultRecordFieldName, defaultConnectionFieldName, defaultOrderByTypeName, buildRecordQuery, buildListQuery, queryableFieldNames, RELATION_FIELDTYPES, } from './plugin/postgraphile';
|
|
23
|
-
// Client
|
|
24
|
-
export { StonecropClient } from './client';
|
package/dist/src/types/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query-builders.test.d.ts","sourceRoot":"","sources":["../../tests/query-builders.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { defaultRecordFieldName, defaultConnectionFieldName, defaultOrderByTypeName, buildRecordQuery, buildListQuery, queryableFieldNames, RELATION_FIELDTYPES, } from '../src/plugin/postgraphile';
|
|
3
|
-
// ---------------------------------------------------------------------------
|
|
4
|
-
// Test fixtures
|
|
5
|
-
// ---------------------------------------------------------------------------
|
|
6
|
-
/** A simple doctype with only scalar fields */
|
|
7
|
-
const scalarOnlyMeta = {
|
|
8
|
-
name: 'Resource',
|
|
9
|
-
tableName: 'resources',
|
|
10
|
-
fields: [
|
|
11
|
-
{ fieldname: 'id', fieldtype: 'Data', label: 'ID' },
|
|
12
|
-
{ fieldname: 'name', fieldtype: 'Data', label: 'Name' },
|
|
13
|
-
{ fieldname: 'quantity', fieldtype: 'Int', label: 'Quantity' },
|
|
14
|
-
{ fieldname: 'is_active', fieldtype: 'Check', label: 'Active' },
|
|
15
|
-
],
|
|
16
|
-
};
|
|
17
|
-
/** A doctype that includes Link and Doctype (relation) fields alongside scalars */
|
|
18
|
-
const mixedFieldsMeta = {
|
|
19
|
-
name: 'Recipe',
|
|
20
|
-
tableName: 'recipes',
|
|
21
|
-
fields: [
|
|
22
|
-
{ fieldname: 'id', fieldtype: 'Data', label: 'ID' },
|
|
23
|
-
{ fieldname: 'title', fieldtype: 'Data', label: 'Title' },
|
|
24
|
-
{ fieldname: 'created_at', fieldtype: 'Datetime', label: 'Created' },
|
|
25
|
-
// FK object reference — requires sub-selection, should be skipped
|
|
26
|
-
{ fieldname: 'userByCreatedBy', fieldtype: 'Link', label: 'Creator', options: 'user' },
|
|
27
|
-
// Reverse relation connection — requires sub-selection, should be skipped
|
|
28
|
-
{
|
|
29
|
-
fieldname: 'recipeIngredientsByRecipeId',
|
|
30
|
-
fieldtype: 'Doctype',
|
|
31
|
-
label: 'Ingredients',
|
|
32
|
-
options: 'recipe-ingredient',
|
|
33
|
-
},
|
|
34
|
-
{ fieldname: 'rating', fieldtype: 'Float', label: 'Rating' },
|
|
35
|
-
],
|
|
36
|
-
};
|
|
37
|
-
// ===========================================================================
|
|
38
|
-
// Inflection helpers
|
|
39
|
-
// ===========================================================================
|
|
40
|
-
describe('defaultRecordFieldName', () => {
|
|
41
|
-
it('singularizes regular plurals and appends ById', () => {
|
|
42
|
-
expect(defaultRecordFieldName('resources')).toBe('resourceById');
|
|
43
|
-
});
|
|
44
|
-
it('handles irregular plurals (statuses → status)', () => {
|
|
45
|
-
expect(defaultRecordFieldName('statuses')).toBe('statusById');
|
|
46
|
-
});
|
|
47
|
-
it('handles irregular plurals (categories → category)', () => {
|
|
48
|
-
expect(defaultRecordFieldName('categories')).toBe('categoryById');
|
|
49
|
-
});
|
|
50
|
-
it('handles irregular plurals (addresses → address)', () => {
|
|
51
|
-
expect(defaultRecordFieldName('addresses')).toBe('addressById');
|
|
52
|
-
});
|
|
53
|
-
it('handles snake_case table names', () => {
|
|
54
|
-
expect(defaultRecordFieldName('sales_orders')).toBe('salesOrderById');
|
|
55
|
-
});
|
|
56
|
-
it('handles already-singular names', () => {
|
|
57
|
-
expect(defaultRecordFieldName('resource')).toBe('resourceById');
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
describe('defaultConnectionFieldName', () => {
|
|
61
|
-
it('prefixes with "all" and PascalCases', () => {
|
|
62
|
-
expect(defaultConnectionFieldName('resources')).toBe('allResources');
|
|
63
|
-
});
|
|
64
|
-
it('handles snake_case', () => {
|
|
65
|
-
expect(defaultConnectionFieldName('sales_orders')).toBe('allSalesOrders');
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
describe('defaultOrderByTypeName', () => {
|
|
69
|
-
it('PascalCases and appends OrderBy', () => {
|
|
70
|
-
expect(defaultOrderByTypeName('resources')).toBe('ResourcesOrderBy');
|
|
71
|
-
});
|
|
72
|
-
it('handles snake_case', () => {
|
|
73
|
-
expect(defaultOrderByTypeName('sales_orders')).toBe('SalesOrdersOrderBy');
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
// ===========================================================================
|
|
77
|
-
// Query builders — relation field filtering (Issue 5)
|
|
78
|
-
// ===========================================================================
|
|
79
|
-
describe('queryableFieldNames', () => {
|
|
80
|
-
it('returns all fields when none are relational', () => {
|
|
81
|
-
const names = queryableFieldNames(scalarOnlyMeta);
|
|
82
|
-
expect(names).toContain('id');
|
|
83
|
-
expect(names).toContain('name');
|
|
84
|
-
expect(names).toContain('quantity');
|
|
85
|
-
expect(names).toContain('is_active');
|
|
86
|
-
});
|
|
87
|
-
it('excludes Link and Doctype fields', () => {
|
|
88
|
-
const names = queryableFieldNames(mixedFieldsMeta);
|
|
89
|
-
expect(names).toContain('id');
|
|
90
|
-
expect(names).toContain('title');
|
|
91
|
-
expect(names).toContain('created_at');
|
|
92
|
-
expect(names).toContain('rating');
|
|
93
|
-
expect(names).not.toContain('userByCreatedBy');
|
|
94
|
-
expect(names).not.toContain('recipeIngredientsByRecipeId');
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
describe('RELATION_FIELDTYPES', () => {
|
|
98
|
-
it('contains Link and Doctype', () => {
|
|
99
|
-
expect(RELATION_FIELDTYPES.has('Link')).toBe(true);
|
|
100
|
-
expect(RELATION_FIELDTYPES.has('Doctype')).toBe(true);
|
|
101
|
-
});
|
|
102
|
-
it('does not contain scalar types', () => {
|
|
103
|
-
expect(RELATION_FIELDTYPES.has('Data')).toBe(false);
|
|
104
|
-
expect(RELATION_FIELDTYPES.has('Int')).toBe(false);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
// ===========================================================================
|
|
108
|
-
// buildRecordQuery
|
|
109
|
-
// ===========================================================================
|
|
110
|
-
describe('buildRecordQuery', () => {
|
|
111
|
-
it('generates valid query with only scalar fields', () => {
|
|
112
|
-
const query = buildRecordQuery(scalarOnlyMeta, defaultRecordFieldName);
|
|
113
|
-
expect(query).toContain('query GetRecord($id: UUID!)');
|
|
114
|
-
expect(query).toContain('resourceById(id: $id)');
|
|
115
|
-
expect(query).toContain('id');
|
|
116
|
-
expect(query).toContain('name');
|
|
117
|
-
expect(query).toContain('quantity');
|
|
118
|
-
});
|
|
119
|
-
it('excludes relation fields from selection', () => {
|
|
120
|
-
const query = buildRecordQuery(mixedFieldsMeta, defaultRecordFieldName);
|
|
121
|
-
expect(query).toContain('title');
|
|
122
|
-
expect(query).toContain('rating');
|
|
123
|
-
expect(query).not.toContain('userByCreatedBy');
|
|
124
|
-
expect(query).not.toContain('recipeIngredientsByRecipeId');
|
|
125
|
-
});
|
|
126
|
-
it('uses custom recordFieldName inflection', () => {
|
|
127
|
-
const customInflection = (t) => `${t}ByRowId`;
|
|
128
|
-
const query = buildRecordQuery(scalarOnlyMeta, customInflection);
|
|
129
|
-
expect(query).toContain('resourcesByRowId(id: $id)');
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
// ===========================================================================
|
|
133
|
-
// buildListQuery — variable declarations (Issue 3)
|
|
134
|
-
// ===========================================================================
|
|
135
|
-
describe('buildListQuery', () => {
|
|
136
|
-
const identity = (t) => t;
|
|
137
|
-
it('declares no variables when no args are provided', () => {
|
|
138
|
-
const query = buildListQuery(scalarOnlyMeta, {}, defaultConnectionFieldName, defaultOrderByTypeName);
|
|
139
|
-
// Should be just "query GetRecords {" with no parenthesized variable declarations
|
|
140
|
-
expect(query).toMatch(/query GetRecords\s*\{/);
|
|
141
|
-
expect(query).not.toContain('$limit');
|
|
142
|
-
expect(query).not.toContain('$offset');
|
|
143
|
-
expect(query).not.toContain('$orderBy');
|
|
144
|
-
});
|
|
145
|
-
it('declares only $limit when only limit is provided', () => {
|
|
146
|
-
const query = buildListQuery(scalarOnlyMeta, { limit: 10 }, defaultConnectionFieldName, defaultOrderByTypeName);
|
|
147
|
-
expect(query).toContain('$limit: Int');
|
|
148
|
-
expect(query).toContain('first: $limit');
|
|
149
|
-
expect(query).not.toContain('$offset');
|
|
150
|
-
expect(query).not.toContain('$orderBy');
|
|
151
|
-
});
|
|
152
|
-
it('declares only $limit and $offset when both are provided', () => {
|
|
153
|
-
const query = buildListQuery(scalarOnlyMeta, { limit: 10, offset: 20 }, defaultConnectionFieldName, defaultOrderByTypeName);
|
|
154
|
-
expect(query).toContain('$limit: Int');
|
|
155
|
-
expect(query).toContain('$offset: Int');
|
|
156
|
-
expect(query).not.toContain('$orderBy');
|
|
157
|
-
});
|
|
158
|
-
it('declares all three variables when all args are provided', () => {
|
|
159
|
-
const query = buildListQuery(scalarOnlyMeta, { limit: 10, offset: 20, orderBy: 'NAME_ASC' }, defaultConnectionFieldName, defaultOrderByTypeName);
|
|
160
|
-
expect(query).toContain('$limit: Int');
|
|
161
|
-
expect(query).toContain('$offset: Int');
|
|
162
|
-
expect(query).toContain('$orderBy: [ResourcesOrderBy!]');
|
|
163
|
-
expect(query).toContain('first: $limit');
|
|
164
|
-
expect(query).toContain('offset: $offset');
|
|
165
|
-
expect(query).toContain('orderBy: $orderBy');
|
|
166
|
-
});
|
|
167
|
-
it('uses correct connection field name', () => {
|
|
168
|
-
const query = buildListQuery(scalarOnlyMeta, {}, defaultConnectionFieldName, defaultOrderByTypeName);
|
|
169
|
-
expect(query).toContain('allResources');
|
|
170
|
-
});
|
|
171
|
-
it('excludes relation fields from selection', () => {
|
|
172
|
-
const query = buildListQuery(mixedFieldsMeta, {}, defaultConnectionFieldName, defaultOrderByTypeName);
|
|
173
|
-
expect(query).toContain('title');
|
|
174
|
-
expect(query).toContain('rating');
|
|
175
|
-
expect(query).not.toContain('userByCreatedBy');
|
|
176
|
-
expect(query).not.toContain('recipeIngredientsByRecipeId');
|
|
177
|
-
});
|
|
178
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registry.test.d.ts","sourceRoot":"","sources":["../../tests/registry.test.ts"],"names":[],"mappings":""}
|
|
File without changes
|