@constructive-io/graphql-codegen 4.28.6 → 4.29.1
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/core/codegen/cli/index.d.ts +0 -2
- package/core/codegen/cli/index.js +0 -4
- package/core/codegen/cli/table-command-generator.d.ts +0 -2
- package/core/codegen/cli/table-command-generator.js +14 -25
- package/core/codegen/index.js +0 -3
- package/core/codegen/orm/index.js +2 -3
- package/core/codegen/orm/input-types-generator.d.ts +1 -3
- package/core/codegen/orm/input-types-generator.js +3 -113
- package/core/codegen/orm/model-generator.d.ts +2 -6
- package/core/codegen/orm/model-generator.js +2 -27
- package/core/codegen/orm/select-types.d.ts +2 -4
- package/core/codegen/queries.d.ts +0 -1
- package/core/codegen/queries.js +1 -7
- package/core/codegen/templates/cli-utils.ts +1 -5
- package/core/codegen/templates/query-builder.ts +3 -26
- package/core/codegen/templates/select-types.ts +2 -4
- package/core/generate.js +0 -2
- package/esm/core/codegen/cli/index.d.ts +0 -2
- package/esm/core/codegen/cli/index.js +0 -4
- package/esm/core/codegen/cli/table-command-generator.d.ts +0 -2
- package/esm/core/codegen/cli/table-command-generator.js +15 -26
- package/esm/core/codegen/index.js +0 -3
- package/esm/core/codegen/orm/index.js +2 -3
- package/esm/core/codegen/orm/input-types-generator.d.ts +1 -3
- package/esm/core/codegen/orm/input-types-generator.js +4 -114
- package/esm/core/codegen/orm/model-generator.d.ts +2 -6
- package/esm/core/codegen/orm/model-generator.js +2 -27
- package/esm/core/codegen/orm/select-types.d.ts +2 -4
- package/esm/core/codegen/queries.d.ts +0 -1
- package/esm/core/codegen/queries.js +2 -8
- package/esm/core/generate.js +0 -2
- package/package.json +7 -7
|
@@ -201,13 +201,12 @@ export function buildSelections(
|
|
|
201
201
|
// Document Builders
|
|
202
202
|
// ============================================================================
|
|
203
203
|
|
|
204
|
-
export function buildFindManyDocument<TSelect, TWhere
|
|
204
|
+
export function buildFindManyDocument<TSelect, TWhere>(
|
|
205
205
|
operationName: string,
|
|
206
206
|
queryField: string,
|
|
207
207
|
select: TSelect,
|
|
208
208
|
args: {
|
|
209
209
|
where?: TWhere;
|
|
210
|
-
condition?: TCondition;
|
|
211
210
|
orderBy?: string[];
|
|
212
211
|
first?: number;
|
|
213
212
|
last?: number;
|
|
@@ -218,7 +217,6 @@ export function buildFindManyDocument<TSelect, TWhere, TCondition = never>(
|
|
|
218
217
|
filterTypeName: string,
|
|
219
218
|
orderByTypeName: string,
|
|
220
219
|
connectionFieldsMap?: Record<string, Record<string, string>>,
|
|
221
|
-
conditionTypeName?: string,
|
|
222
220
|
): { document: string; variables: Record<string, unknown> } {
|
|
223
221
|
const selections = select
|
|
224
222
|
? buildSelections(
|
|
@@ -232,16 +230,6 @@ export function buildFindManyDocument<TSelect, TWhere, TCondition = never>(
|
|
|
232
230
|
const queryArgs: ArgumentNode[] = [];
|
|
233
231
|
const variables: Record<string, unknown> = {};
|
|
234
232
|
|
|
235
|
-
addVariable(
|
|
236
|
-
{
|
|
237
|
-
varName: 'condition',
|
|
238
|
-
typeName: conditionTypeName,
|
|
239
|
-
value: args.condition,
|
|
240
|
-
},
|
|
241
|
-
variableDefinitions,
|
|
242
|
-
queryArgs,
|
|
243
|
-
variables,
|
|
244
|
-
);
|
|
245
233
|
addVariable(
|
|
246
234
|
{
|
|
247
235
|
varName: 'where',
|
|
@@ -319,14 +307,13 @@ export function buildFindManyDocument<TSelect, TWhere, TCondition = never>(
|
|
|
319
307
|
return { document: print(document), variables };
|
|
320
308
|
}
|
|
321
309
|
|
|
322
|
-
export function buildFindFirstDocument<TSelect, TWhere
|
|
310
|
+
export function buildFindFirstDocument<TSelect, TWhere>(
|
|
323
311
|
operationName: string,
|
|
324
312
|
queryField: string,
|
|
325
313
|
select: TSelect,
|
|
326
|
-
args: { where?: TWhere
|
|
314
|
+
args: { where?: TWhere },
|
|
327
315
|
filterTypeName: string,
|
|
328
316
|
connectionFieldsMap?: Record<string, Record<string, string>>,
|
|
329
|
-
conditionTypeName?: string,
|
|
330
317
|
): { document: string; variables: Record<string, unknown> } {
|
|
331
318
|
const selections = select
|
|
332
319
|
? buildSelections(
|
|
@@ -347,16 +334,6 @@ export function buildFindFirstDocument<TSelect, TWhere, TCondition = never>(
|
|
|
347
334
|
queryArgs,
|
|
348
335
|
variables,
|
|
349
336
|
);
|
|
350
|
-
addVariable(
|
|
351
|
-
{
|
|
352
|
-
varName: 'condition',
|
|
353
|
-
typeName: conditionTypeName,
|
|
354
|
-
value: args.condition,
|
|
355
|
-
},
|
|
356
|
-
variableDefinitions,
|
|
357
|
-
queryArgs,
|
|
358
|
-
variables,
|
|
359
|
-
);
|
|
360
337
|
addVariable(
|
|
361
338
|
{
|
|
362
339
|
varName: 'where',
|
|
@@ -21,10 +21,9 @@ export interface PageInfo {
|
|
|
21
21
|
endCursor?: string | null;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export interface FindManyArgs<TSelect, TWhere,
|
|
24
|
+
export interface FindManyArgs<TSelect, TWhere, TOrderBy = never> {
|
|
25
25
|
select?: TSelect;
|
|
26
26
|
where?: TWhere;
|
|
27
|
-
condition?: TCondition;
|
|
28
27
|
orderBy?: TOrderBy[];
|
|
29
28
|
first?: number;
|
|
30
29
|
last?: number;
|
|
@@ -33,10 +32,9 @@ export interface FindManyArgs<TSelect, TWhere, TCondition = never, TOrderBy = ne
|
|
|
33
32
|
offset?: number;
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
export interface FindFirstArgs<TSelect, TWhere
|
|
35
|
+
export interface FindFirstArgs<TSelect, TWhere> {
|
|
37
36
|
select?: TSelect;
|
|
38
37
|
where?: TWhere;
|
|
39
|
-
condition?: TCondition;
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
export interface CreateArgs<TSelect, TData> {
|
package/core/generate.js
CHANGED
|
@@ -587,14 +587,12 @@ async function generateMulti(options) {
|
|
|
587
587
|
const firstTargetConfig = configs[names[0]];
|
|
588
588
|
const multiNodeHttpAdapter = firstTargetConfig?.nodeHttpAdapter === true ||
|
|
589
589
|
(firstTargetConfig?.nodeHttpAdapter !== false);
|
|
590
|
-
const multiConditionEnabled = firstTargetConfig?.codegen?.condition === true;
|
|
591
590
|
const { files } = (0, cli_1.generateMultiTargetCli)({
|
|
592
591
|
toolName,
|
|
593
592
|
builtinNames: cliConfig.builtinNames,
|
|
594
593
|
targets: cliTargets,
|
|
595
594
|
nodeHttpAdapter: multiNodeHttpAdapter,
|
|
596
595
|
entryPoint: cliConfig.entryPoint,
|
|
597
|
-
condition: multiConditionEnabled,
|
|
598
596
|
});
|
|
599
597
|
const cliFilesToWrite = files.map((file) => ({
|
|
600
598
|
path: node_path_1.default.posix.join('cli', file.fileName),
|
|
@@ -43,8 +43,6 @@ export interface GenerateMultiTargetCliOptions {
|
|
|
43
43
|
nodeHttpAdapter?: boolean;
|
|
44
44
|
/** Generate a runnable index.ts entry point */
|
|
45
45
|
entryPoint?: boolean;
|
|
46
|
-
/** Whether PostGraphile condition types are enabled (default: true) */
|
|
47
|
-
condition?: boolean;
|
|
48
46
|
}
|
|
49
47
|
export declare function resolveBuiltinNames(targetNames: string[], userOverrides?: BuiltinNames): {
|
|
50
48
|
auth: string;
|
|
@@ -34,11 +34,9 @@ export function generateCli(options) {
|
|
|
34
34
|
files.push(contextFile);
|
|
35
35
|
const authFile = generateAuthCommand(toolName);
|
|
36
36
|
files.push(authFile);
|
|
37
|
-
const conditionEnabled = config.codegen?.condition === true;
|
|
38
37
|
for (const table of tables) {
|
|
39
38
|
const tableFile = generateTableCommand(table, {
|
|
40
39
|
typeRegistry: options.typeRegistry,
|
|
41
|
-
condition: conditionEnabled,
|
|
42
40
|
});
|
|
43
41
|
files.push(tableFile);
|
|
44
42
|
}
|
|
@@ -85,7 +83,6 @@ export function resolveBuiltinNames(targetNames, userOverrides) {
|
|
|
85
83
|
}
|
|
86
84
|
export function generateMultiTargetCli(options) {
|
|
87
85
|
const { toolName, targets } = options;
|
|
88
|
-
const conditionEnabled = options.condition === true;
|
|
89
86
|
const files = [];
|
|
90
87
|
const targetNames = targets.map((t) => t.name);
|
|
91
88
|
const builtinNames = resolveBuiltinNames(targetNames, options.builtinNames);
|
|
@@ -135,7 +132,6 @@ export function generateMultiTargetCli(options) {
|
|
|
135
132
|
targetName: target.name,
|
|
136
133
|
executorImportPath: '../../executor',
|
|
137
134
|
typeRegistry: target.typeRegistry,
|
|
138
|
-
condition: conditionEnabled,
|
|
139
135
|
});
|
|
140
136
|
files.push(tableFile);
|
|
141
137
|
}
|
|
@@ -6,7 +6,5 @@ export interface TableCommandOptions {
|
|
|
6
6
|
executorImportPath?: string;
|
|
7
7
|
/** TypeRegistry from introspection, used to check field defaults */
|
|
8
8
|
typeRegistry?: TypeRegistry;
|
|
9
|
-
/** Whether PostGraphile condition types are enabled (default: true) */
|
|
10
|
-
condition?: boolean;
|
|
11
9
|
}
|
|
12
10
|
export declare function generateTableCommand(table: Table, options?: TableCommandOptions): GeneratedFile;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as t from '@babel/types';
|
|
2
2
|
import { toKebabCase } from 'inflekt';
|
|
3
3
|
import { generateCode } from '../babel-ast';
|
|
4
|
-
import { getGeneratedFileHeader, getPrimaryKeyInfo, getScalarFields, getSelectableScalarFields, getTableNames, getWritableFieldNames, resolveInnerInputType, ucFirst, lcFirst, toPascalCase, getCreateInputTypeName, getPatchTypeName, getFilterTypeName, getOrderByTypeName,
|
|
4
|
+
import { getGeneratedFileHeader, getPrimaryKeyInfo, getScalarFields, getSelectableScalarFields, getTableNames, getWritableFieldNames, resolveInnerInputType, ucFirst, lcFirst, toPascalCase, getCreateInputTypeName, getPatchTypeName, getFilterTypeName, getOrderByTypeName, } from '../utils';
|
|
5
5
|
import { categorizeSpecialFields } from '../docs-utils';
|
|
6
6
|
function createImportDeclaration(moduleSpecifier, namedImports, typeOnly = false) {
|
|
7
7
|
const specifiers = namedImports.map((name) => t.importSpecifier(t.identifier(name), t.identifier(name)));
|
|
@@ -249,24 +249,20 @@ function buildAutoEmbedInputBlock(vectorFieldNames) {
|
|
|
249
249
|
}
|
|
250
250
|
/**
|
|
251
251
|
* Build the FindManyArgs type instantiation for a table:
|
|
252
|
-
* FindManyArgs<SelectType, FilterType,
|
|
252
|
+
* FindManyArgs<SelectType, FilterType, OrderByType> & { select: SelectType }
|
|
253
253
|
*
|
|
254
254
|
* The intersection with { select: SelectType } makes select required,
|
|
255
255
|
* matching what the ORM's findMany method expects. parseFindManyArgs
|
|
256
256
|
* always sets select at runtime (from defaultSelect or --select flag).
|
|
257
257
|
*/
|
|
258
|
-
function buildFindManyArgsType(table
|
|
258
|
+
function buildFindManyArgsType(table) {
|
|
259
259
|
const { typeName } = getTableNames(table);
|
|
260
260
|
const selectTypeName = `${typeName}Select`;
|
|
261
261
|
const whereTypeName = getFilterTypeName(table);
|
|
262
|
-
const conditionTypeName = conditionEnabled ? getConditionTypeName(table) : undefined;
|
|
263
262
|
const orderByTypeName = getOrderByTypeName(table);
|
|
264
263
|
const findManyType = t.tsTypeReference(t.identifier('FindManyArgs'), t.tsTypeParameterInstantiation([
|
|
265
264
|
t.tsTypeReference(t.identifier(selectTypeName)),
|
|
266
265
|
t.tsTypeReference(t.identifier(whereTypeName)),
|
|
267
|
-
conditionTypeName
|
|
268
|
-
? t.tsTypeReference(t.identifier(conditionTypeName))
|
|
269
|
-
: t.tsNeverKeyword(),
|
|
270
266
|
t.tsTypeReference(t.identifier(orderByTypeName)),
|
|
271
267
|
]));
|
|
272
268
|
// Intersect with { select: SelectType } to make select required
|
|
@@ -279,22 +275,18 @@ function buildFindManyArgsType(table, conditionEnabled) {
|
|
|
279
275
|
}
|
|
280
276
|
/**
|
|
281
277
|
* Build the FindFirstArgs type instantiation for a table:
|
|
282
|
-
* FindFirstArgs<SelectType, FilterType
|
|
278
|
+
* FindFirstArgs<SelectType, FilterType> & { select: SelectType }
|
|
283
279
|
*
|
|
284
280
|
* The intersection with { select: SelectType } makes select required,
|
|
285
281
|
* matching what the ORM's findFirst method expects.
|
|
286
282
|
*/
|
|
287
|
-
function buildFindFirstArgsType(table
|
|
283
|
+
function buildFindFirstArgsType(table) {
|
|
288
284
|
const { typeName } = getTableNames(table);
|
|
289
285
|
const selectTypeName = `${typeName}Select`;
|
|
290
286
|
const whereTypeName = getFilterTypeName(table);
|
|
291
|
-
const conditionTypeName = conditionEnabled ? getConditionTypeName(table) : undefined;
|
|
292
287
|
const findFirstType = t.tsTypeReference(t.identifier('FindFirstArgs'), t.tsTypeParameterInstantiation([
|
|
293
288
|
t.tsTypeReference(t.identifier(selectTypeName)),
|
|
294
289
|
t.tsTypeReference(t.identifier(whereTypeName)),
|
|
295
|
-
conditionTypeName
|
|
296
|
-
? t.tsTypeReference(t.identifier(conditionTypeName))
|
|
297
|
-
: t.tsNeverKeyword(),
|
|
298
290
|
]));
|
|
299
291
|
// Intersect with { select: SelectType } to make select required
|
|
300
292
|
return t.tsIntersectionType([
|
|
@@ -304,7 +296,7 @@ function buildFindFirstArgsType(table, conditionEnabled) {
|
|
|
304
296
|
]),
|
|
305
297
|
]);
|
|
306
298
|
}
|
|
307
|
-
function buildListHandler(table, vectorFieldNames, targetName, typeRegistry
|
|
299
|
+
function buildListHandler(table, vectorFieldNames, targetName, typeRegistry) {
|
|
308
300
|
const { singularName } = getTableNames(table);
|
|
309
301
|
const defaultSelectObj = buildSelectObject(table, typeRegistry);
|
|
310
302
|
// --- Build the try body ---
|
|
@@ -320,7 +312,7 @@ function buildListHandler(table, vectorFieldNames, targetName, typeRegistry, con
|
|
|
320
312
|
t.identifier('defaultSelect'),
|
|
321
313
|
]);
|
|
322
314
|
callExpr.typeParameters = t.tsTypeParameterInstantiation([
|
|
323
|
-
buildFindManyArgsType(table
|
|
315
|
+
buildFindManyArgsType(table),
|
|
324
316
|
]);
|
|
325
317
|
tryBody.push(t.variableDeclaration('const', [
|
|
326
318
|
t.variableDeclarator(t.identifier('findManyArgs'), callExpr),
|
|
@@ -346,10 +338,10 @@ function buildListHandler(table, vectorFieldNames, targetName, typeRegistry, con
|
|
|
346
338
|
}
|
|
347
339
|
/**
|
|
348
340
|
* Build a `handleFindFirst` function — CLI equivalent of the TS SDK's findFirst().
|
|
349
|
-
* Accepts --select, --where.<field>.<op
|
|
341
|
+
* Accepts --select, --where.<field>.<op> flags.
|
|
350
342
|
* Internally calls findMany with first:1 and returns a single record (or null).
|
|
351
343
|
*/
|
|
352
|
-
function buildFindFirstHandler(table, targetName, typeRegistry
|
|
344
|
+
function buildFindFirstHandler(table, targetName, typeRegistry) {
|
|
353
345
|
const { singularName } = getTableNames(table);
|
|
354
346
|
const defaultSelectObj = buildSelectObject(table, typeRegistry);
|
|
355
347
|
const tryBody = [];
|
|
@@ -364,7 +356,7 @@ function buildFindFirstHandler(table, targetName, typeRegistry, conditionEnabled
|
|
|
364
356
|
t.identifier('defaultSelect'),
|
|
365
357
|
]);
|
|
366
358
|
callExpr.typeParameters = t.tsTypeParameterInstantiation([
|
|
367
|
-
buildFindFirstArgsType(table
|
|
359
|
+
buildFindFirstArgsType(table),
|
|
368
360
|
]);
|
|
369
361
|
tryBody.push(t.variableDeclaration('const', [
|
|
370
362
|
t.variableDeclarator(t.identifier('findFirstArgs'), callExpr),
|
|
@@ -390,7 +382,7 @@ function buildFindFirstHandler(table, targetName, typeRegistry, conditionEnabled
|
|
|
390
382
|
* `where` clause that targets all detected search fields (tsvector, BM25,
|
|
391
383
|
* trigram, vector embedding). Supports --limit, --offset, --select, --orderBy.
|
|
392
384
|
*/
|
|
393
|
-
function buildSearchHandler(table, specialGroups, vectorFieldNames, targetName, typeRegistry
|
|
385
|
+
function buildSearchHandler(table, specialGroups, vectorFieldNames, targetName, typeRegistry) {
|
|
394
386
|
const { singularName } = getTableNames(table);
|
|
395
387
|
const defaultSelectObj = buildSelectObject(table, typeRegistry);
|
|
396
388
|
const tryBody = [];
|
|
@@ -464,7 +456,7 @@ function buildSearchHandler(table, specialGroups, vectorFieldNames, targetName,
|
|
|
464
456
|
t.identifier('searchWhere'),
|
|
465
457
|
]);
|
|
466
458
|
callExpr.typeParameters = t.tsTypeParameterInstantiation([
|
|
467
|
-
buildFindManyArgsType(table
|
|
459
|
+
buildFindManyArgsType(table),
|
|
468
460
|
]);
|
|
469
461
|
tryBody.push(t.variableDeclaration('const', [
|
|
470
462
|
t.variableDeclarator(t.identifier('findManyArgs'), callExpr),
|
|
@@ -717,14 +709,11 @@ export function generateTableCommand(table, options) {
|
|
|
717
709
|
const selectTypeName = `${typeName}Select`;
|
|
718
710
|
const whereTypeName = getFilterTypeName(table);
|
|
719
711
|
const orderByTypeName = getOrderByTypeName(table);
|
|
720
|
-
const conditionEnabled = options?.condition === true;
|
|
721
|
-
const conditionTypeName = conditionEnabled ? getConditionTypeName(table) : undefined;
|
|
722
712
|
statements.push(createImportDeclaration(inputTypesPath, [
|
|
723
713
|
createInputTypeName,
|
|
724
714
|
patchTypeName,
|
|
725
715
|
selectTypeName,
|
|
726
716
|
whereTypeName,
|
|
727
|
-
...(conditionTypeName ? [conditionTypeName] : []),
|
|
728
717
|
orderByTypeName,
|
|
729
718
|
], true));
|
|
730
719
|
// Import FindManyArgs/FindFirstArgs from select-types for proper generic typing
|
|
@@ -869,10 +858,10 @@ export function generateTableCommand(table, options) {
|
|
|
869
858
|
]), false, true));
|
|
870
859
|
const tn = options?.targetName;
|
|
871
860
|
const ormTypes = { createInputTypeName, patchTypeName, innerFieldName };
|
|
872
|
-
statements.push(buildListHandler(table, vectorFieldNames, tn, options?.typeRegistry
|
|
873
|
-
statements.push(buildFindFirstHandler(table, tn, options?.typeRegistry
|
|
861
|
+
statements.push(buildListHandler(table, vectorFieldNames, tn, options?.typeRegistry));
|
|
862
|
+
statements.push(buildFindFirstHandler(table, tn, options?.typeRegistry));
|
|
874
863
|
if (hasSearchFields)
|
|
875
|
-
statements.push(buildSearchHandler(table, specialGroups, vectorFieldNames, tn, options?.typeRegistry
|
|
864
|
+
statements.push(buildSearchHandler(table, specialGroups, vectorFieldNames, tn, options?.typeRegistry));
|
|
876
865
|
if (hasGet)
|
|
877
866
|
statements.push(buildGetHandler(table, tn, options?.typeRegistry));
|
|
878
867
|
statements.push(buildMutationHandler(table, 'create', vectorFieldNames, tn, options?.typeRegistry, ormTypes));
|
|
@@ -91,14 +91,11 @@ export function generate(options) {
|
|
|
91
91
|
});
|
|
92
92
|
hasInvalidation = true;
|
|
93
93
|
}
|
|
94
|
-
// Condition types (PostGraphile simple equality filters)
|
|
95
|
-
const conditionEnabled = config.codegen?.condition === true;
|
|
96
94
|
// 4. Generate table-based query hooks (queries/*.ts)
|
|
97
95
|
const queryHooks = generateAllQueryHooks(tables, {
|
|
98
96
|
reactQueryEnabled,
|
|
99
97
|
useCentralizedKeys,
|
|
100
98
|
hasRelationships,
|
|
101
|
-
condition: conditionEnabled,
|
|
102
99
|
});
|
|
103
100
|
for (const hook of queryHooks) {
|
|
104
101
|
files.push({
|
|
@@ -9,7 +9,6 @@ import { generateAllModelFiles } from './model-generator';
|
|
|
9
9
|
export function generateOrm(options) {
|
|
10
10
|
const { tables, customOperations, sharedTypesPath } = options;
|
|
11
11
|
const commentsEnabled = options.config.codegen?.comments !== false;
|
|
12
|
-
const conditionEnabled = options.config.codegen?.condition === true;
|
|
13
12
|
const files = [];
|
|
14
13
|
// Use shared types when a sharedTypesPath is provided (unified output mode)
|
|
15
14
|
const useSharedTypes = !!sharedTypesPath;
|
|
@@ -30,7 +29,7 @@ export function generateOrm(options) {
|
|
|
30
29
|
content: selectTypesFile.content,
|
|
31
30
|
});
|
|
32
31
|
// 2. Generate model files
|
|
33
|
-
const modelFiles = generateAllModelFiles(tables, useSharedTypes
|
|
32
|
+
const modelFiles = generateAllModelFiles(tables, useSharedTypes);
|
|
34
33
|
for (const modelFile of modelFiles) {
|
|
35
34
|
files.push({
|
|
36
35
|
path: `models/${modelFile.fileName}`,
|
|
@@ -67,7 +66,7 @@ export function generateOrm(options) {
|
|
|
67
66
|
}
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
|
-
const inputTypesFile = generateInputTypesFile(typeRegistry ?? new Map(), usedInputTypes, tables, usedPayloadTypes, commentsEnabled
|
|
69
|
+
const inputTypesFile = generateInputTypesFile(typeRegistry ?? new Map(), usedInputTypes, tables, usedPayloadTypes, commentsEnabled);
|
|
71
70
|
files.push({
|
|
72
71
|
path: inputTypesFile.fileName,
|
|
73
72
|
content: inputTypesFile.content,
|
|
@@ -18,6 +18,4 @@ export declare function collectPayloadTypeNames(operations: Array<{
|
|
|
18
18
|
/**
|
|
19
19
|
* Generate comprehensive input-types.ts file using Babel AST
|
|
20
20
|
*/
|
|
21
|
-
export declare function generateInputTypesFile(typeRegistry: TypeRegistry, usedInputTypes: Set<string>, tables?: Table[], usedPayloadTypes?: Set<string>, comments?: boolean
|
|
22
|
-
condition?: boolean;
|
|
23
|
-
}): GeneratedInputTypesFile;
|
|
21
|
+
export declare function generateInputTypesFile(typeRegistry: TypeRegistry, usedInputTypes: Set<string>, tables?: Table[], usedPayloadTypes?: Set<string>, comments?: boolean): GeneratedInputTypesFile;
|
|
@@ -15,7 +15,7 @@ import { pluralize } from 'inflekt';
|
|
|
15
15
|
import { addJSDocComment, addLineComment, generateCode } from '../babel-ast';
|
|
16
16
|
import { BASE_FILTER_TYPE_NAMES, SCALAR_NAMES, scalarToFilterType, scalarToTsType } from '../scalars';
|
|
17
17
|
import { getTypeBaseName } from '../type-resolver';
|
|
18
|
-
import { getCreateInputTypeName,
|
|
18
|
+
import { getCreateInputTypeName, getFilterTypeName, getGeneratedFileHeader, getOrderByTypeName, getPatchTypeName, getPrimaryKeyInfo, getTableNames, isRelationField, lcFirst, stripSmartComments, } from '../utils';
|
|
19
19
|
// ============================================================================
|
|
20
20
|
// Constants
|
|
21
21
|
// ============================================================================
|
|
@@ -215,8 +215,7 @@ const SCALAR_FILTER_CONFIGS = [
|
|
|
215
215
|
},
|
|
216
216
|
{ name: 'FullTextFilter', tsType: 'string', operators: ['fulltext'] },
|
|
217
217
|
// VectorFilter: equality/distinct operators for vector columns on Filter types.
|
|
218
|
-
//
|
|
219
|
-
// connection-filter may still generate a filter for vector columns. This ensures
|
|
218
|
+
// connection-filter may generate a filter for vector columns. This ensures
|
|
220
219
|
// the generated type uses number[] rather than being silently omitted.
|
|
221
220
|
{ name: 'VectorFilter', tsType: 'number[]', operators: ['equality', 'distinct'] },
|
|
222
221
|
// List filters (for array fields like string[], int[], uuid[])
|
|
@@ -737,69 +736,6 @@ function generateTableFilterTypes(tables, typeRegistry) {
|
|
|
737
736
|
return statements;
|
|
738
737
|
}
|
|
739
738
|
// ============================================================================
|
|
740
|
-
// Condition Types Generator (AST-based)
|
|
741
|
-
// ============================================================================
|
|
742
|
-
/**
|
|
743
|
-
* Build properties for a table condition interface
|
|
744
|
-
* Condition types are simpler than Filter types - they use direct value equality.
|
|
745
|
-
*
|
|
746
|
-
* Also merges any extra fields from the GraphQL schema's condition type
|
|
747
|
-
* (e.g., plugin-injected fields like vectorEmbedding from VectorSearchPlugin)
|
|
748
|
-
* that are not derived from the table's own columns.
|
|
749
|
-
*/
|
|
750
|
-
function buildTableConditionProperties(table, typeRegistry) {
|
|
751
|
-
const properties = [];
|
|
752
|
-
const generatedFieldNames = new Set();
|
|
753
|
-
for (const field of table.fields) {
|
|
754
|
-
const fieldType = typeof field.type === 'string' ? field.type : field.type.gqlType;
|
|
755
|
-
if (isRelationField(field.name, table))
|
|
756
|
-
continue;
|
|
757
|
-
// Condition types use the raw scalar type (nullable)
|
|
758
|
-
const tsType = scalarToTsType(fieldType, { unknownScalar: 'unknown' });
|
|
759
|
-
properties.push({
|
|
760
|
-
name: field.name,
|
|
761
|
-
type: `${tsType} | null`,
|
|
762
|
-
optional: true,
|
|
763
|
-
});
|
|
764
|
-
generatedFieldNames.add(field.name);
|
|
765
|
-
}
|
|
766
|
-
// Merge any additional fields from the schema's condition type
|
|
767
|
-
// (e.g., plugin-added fields like vectorEmbedding from VectorSearchPlugin)
|
|
768
|
-
if (typeRegistry) {
|
|
769
|
-
const conditionTypeName = getConditionTypeName(table);
|
|
770
|
-
const conditionType = typeRegistry.get(conditionTypeName);
|
|
771
|
-
if (conditionType?.kind === 'INPUT_OBJECT' &&
|
|
772
|
-
conditionType.inputFields) {
|
|
773
|
-
for (const field of conditionType.inputFields) {
|
|
774
|
-
if (generatedFieldNames.has(field.name))
|
|
775
|
-
continue;
|
|
776
|
-
const tsType = typeRefToTs(field.type);
|
|
777
|
-
properties.push({
|
|
778
|
-
name: field.name,
|
|
779
|
-
type: tsType,
|
|
780
|
-
optional: true,
|
|
781
|
-
description: stripSmartComments(field.description, true),
|
|
782
|
-
});
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
return properties;
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
|
-
* Generate table condition type statements
|
|
790
|
-
*/
|
|
791
|
-
function generateTableConditionTypes(tables, typeRegistry) {
|
|
792
|
-
const statements = [];
|
|
793
|
-
for (const table of tables) {
|
|
794
|
-
const conditionName = getConditionTypeName(table);
|
|
795
|
-
statements.push(createExportedInterface(conditionName, buildTableConditionProperties(table, typeRegistry)));
|
|
796
|
-
}
|
|
797
|
-
if (statements.length > 0) {
|
|
798
|
-
addSectionComment(statements, 'Table Condition Types');
|
|
799
|
-
}
|
|
800
|
-
return statements;
|
|
801
|
-
}
|
|
802
|
-
// ============================================================================
|
|
803
739
|
// OrderBy Types Generator (AST-based)
|
|
804
740
|
// ============================================================================
|
|
805
741
|
/**
|
|
@@ -1342,47 +1278,13 @@ function collectFilterExtraInputTypes(tables, typeRegistry) {
|
|
|
1342
1278
|
}
|
|
1343
1279
|
return extraTypes;
|
|
1344
1280
|
}
|
|
1345
|
-
/**
|
|
1346
|
-
* Collect extra input type names referenced by plugin-injected condition fields.
|
|
1347
|
-
*
|
|
1348
|
-
* When plugins (like VectorSearchPlugin) inject fields into condition types,
|
|
1349
|
-
* they reference types (like VectorNearbyInput, VectorMetric) that also need
|
|
1350
|
-
* to be generated. This function discovers those types by comparing the
|
|
1351
|
-
* schema's condition type fields against the table's own columns.
|
|
1352
|
-
*/
|
|
1353
|
-
function collectConditionExtraInputTypes(tables, typeRegistry) {
|
|
1354
|
-
const extraTypes = new Set();
|
|
1355
|
-
for (const table of tables) {
|
|
1356
|
-
const conditionTypeName = getConditionTypeName(table);
|
|
1357
|
-
const conditionType = typeRegistry.get(conditionTypeName);
|
|
1358
|
-
if (!conditionType ||
|
|
1359
|
-
conditionType.kind !== 'INPUT_OBJECT' ||
|
|
1360
|
-
!conditionType.inputFields) {
|
|
1361
|
-
continue;
|
|
1362
|
-
}
|
|
1363
|
-
const tableFieldNames = new Set(table.fields
|
|
1364
|
-
.filter((f) => !isRelationField(f.name, table))
|
|
1365
|
-
.map((f) => f.name));
|
|
1366
|
-
for (const field of conditionType.inputFields) {
|
|
1367
|
-
if (tableFieldNames.has(field.name))
|
|
1368
|
-
continue;
|
|
1369
|
-
// Collect the base type name of this extra field
|
|
1370
|
-
const baseName = getTypeBaseName(field.type);
|
|
1371
|
-
if (baseName && !SCALAR_NAMES.has(baseName)) {
|
|
1372
|
-
extraTypes.add(baseName);
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
return extraTypes;
|
|
1377
|
-
}
|
|
1378
1281
|
// ============================================================================
|
|
1379
1282
|
// Main Generator (AST-based)
|
|
1380
1283
|
// ============================================================================
|
|
1381
1284
|
/**
|
|
1382
1285
|
* Generate comprehensive input-types.ts file using Babel AST
|
|
1383
1286
|
*/
|
|
1384
|
-
export function generateInputTypesFile(typeRegistry, usedInputTypes, tables, usedPayloadTypes, comments = true
|
|
1385
|
-
const conditionEnabled = options?.condition === true;
|
|
1287
|
+
export function generateInputTypesFile(typeRegistry, usedInputTypes, tables, usedPayloadTypes, comments = true) {
|
|
1386
1288
|
const statements = [];
|
|
1387
1289
|
const tablesList = tables ?? [];
|
|
1388
1290
|
const hasTables = tablesList.length > 0;
|
|
@@ -1408,12 +1310,6 @@ export function generateInputTypesFile(typeRegistry, usedInputTypes, tables, use
|
|
|
1408
1310
|
// Pass typeRegistry to use schema's filter type as source of truth,
|
|
1409
1311
|
// capturing plugin-injected filter fields (e.g., bm25, tsvector, trgm, vector, geom)
|
|
1410
1312
|
statements.push(...generateTableFilterTypes(tablesList, typeRegistry));
|
|
1411
|
-
// 4b. Table condition types (simple equality filter)
|
|
1412
|
-
// Pass typeRegistry to merge plugin-injected condition fields
|
|
1413
|
-
// (e.g., vectorEmbedding from VectorSearchPlugin)
|
|
1414
|
-
if (conditionEnabled) {
|
|
1415
|
-
statements.push(...generateTableConditionTypes(tablesList, typeRegistry));
|
|
1416
|
-
}
|
|
1417
1313
|
// 5. OrderBy types
|
|
1418
1314
|
// Pass typeRegistry to merge plugin-injected orderBy values
|
|
1419
1315
|
// (e.g., EMBEDDING_DISTANCE_ASC/DESC from VectorSearchPlugin)
|
|
@@ -1425,7 +1321,7 @@ export function generateInputTypesFile(typeRegistry, usedInputTypes, tables, use
|
|
|
1425
1321
|
// Always emit this export so generated model/custom-op imports stay valid.
|
|
1426
1322
|
statements.push(...generateConnectionFieldsMap(tablesList, tableByName));
|
|
1427
1323
|
// 7. Custom input types from TypeRegistry
|
|
1428
|
-
// Also include any extra types referenced by plugin-injected filter
|
|
1324
|
+
// Also include any extra types referenced by plugin-injected filter fields
|
|
1429
1325
|
const mergedUsedInputTypes = new Set(usedInputTypes);
|
|
1430
1326
|
if (hasTables) {
|
|
1431
1327
|
const filterExtraTypes = collectFilterExtraInputTypes(tablesList, typeRegistry);
|
|
@@ -1433,12 +1329,6 @@ export function generateInputTypesFile(typeRegistry, usedInputTypes, tables, use
|
|
|
1433
1329
|
mergedUsedInputTypes.add(typeName);
|
|
1434
1330
|
}
|
|
1435
1331
|
}
|
|
1436
|
-
if (hasTables && conditionEnabled) {
|
|
1437
|
-
const conditionExtraTypes = collectConditionExtraInputTypes(tablesList, typeRegistry);
|
|
1438
|
-
for (const typeName of conditionExtraTypes) {
|
|
1439
|
-
mergedUsedInputTypes.add(typeName);
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
1332
|
const tableCrudTypes = tables ? buildTableCrudTypeNames(tables) : undefined;
|
|
1443
1333
|
// Pass customScalarTypes + enumTypes as already-generated to avoid duplicate declarations
|
|
1444
1334
|
const alreadyGenerated = new Set([
|
|
@@ -5,9 +5,5 @@ export interface GeneratedModelFile {
|
|
|
5
5
|
modelName: string;
|
|
6
6
|
tableName: string;
|
|
7
7
|
}
|
|
8
|
-
export declare function generateModelFile(table: Table, _useSharedTypes: boolean, options?:
|
|
9
|
-
|
|
10
|
-
}, allTables?: Table[]): GeneratedModelFile;
|
|
11
|
-
export declare function generateAllModelFiles(tables: Table[], useSharedTypes: boolean, options?: {
|
|
12
|
-
condition?: boolean;
|
|
13
|
-
}): GeneratedModelFile[];
|
|
8
|
+
export declare function generateModelFile(table: Table, _useSharedTypes: boolean, options?: Record<string, never>, allTables?: Table[]): GeneratedModelFile;
|
|
9
|
+
export declare function generateAllModelFiles(tables: Table[], useSharedTypes: boolean): GeneratedModelFile[];
|
|
@@ -67,7 +67,6 @@ function strictSelectGuard(selectTypeName) {
|
|
|
67
67
|
]));
|
|
68
68
|
}
|
|
69
69
|
export function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
70
|
-
const conditionEnabled = options?.condition === true;
|
|
71
70
|
const { typeName, singularName, pluralName } = getTableNames(table);
|
|
72
71
|
const modelName = `${typeName}Model`;
|
|
73
72
|
const baseFileName = lcFirst(typeName);
|
|
@@ -76,7 +75,6 @@ export function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
76
75
|
const selectTypeName = `${typeName}Select`;
|
|
77
76
|
const relationTypeName = `${typeName}WithRelations`;
|
|
78
77
|
const whereTypeName = getFilterTypeName(table);
|
|
79
|
-
const conditionTypeName = conditionEnabled ? `${typeName}Condition` : undefined;
|
|
80
78
|
const orderByTypeName = getOrderByTypeName(table);
|
|
81
79
|
const createInputTypeName = `Create${typeName}Input`;
|
|
82
80
|
const updateInputTypeName = `Update${typeName}Input`;
|
|
@@ -124,7 +122,6 @@ export function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
124
122
|
relationTypeName,
|
|
125
123
|
selectTypeName,
|
|
126
124
|
whereTypeName,
|
|
127
|
-
...(conditionTypeName ? [conditionTypeName] : []),
|
|
128
125
|
orderByTypeName,
|
|
129
126
|
createInputTypeName,
|
|
130
127
|
updateInputTypeName,
|
|
@@ -147,9 +144,6 @@ export function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
147
144
|
const findManyTypeArgs = [
|
|
148
145
|
(sel) => sel,
|
|
149
146
|
() => t.tsTypeReference(t.identifier(whereTypeName)),
|
|
150
|
-
conditionTypeName
|
|
151
|
-
? () => t.tsTypeReference(t.identifier(conditionTypeName))
|
|
152
|
-
: () => t.tsNeverKeyword(),
|
|
153
147
|
() => t.tsTypeReference(t.identifier(orderByTypeName)),
|
|
154
148
|
];
|
|
155
149
|
const argsType = (sel) => t.tsTypeReference(t.identifier('FindManyArgs'), t.tsTypeParameterInstantiation(findManyTypeArgs.map(fn => fn(sel))));
|
|
@@ -172,11 +166,6 @@ export function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
172
166
|
const selectExpr = t.memberExpression(t.identifier('args'), t.identifier('select'));
|
|
173
167
|
const findManyObjProps = [
|
|
174
168
|
t.objectProperty(t.identifier('where'), t.optionalMemberExpression(t.identifier('args'), t.identifier('where'), false, true)),
|
|
175
|
-
...(conditionTypeName
|
|
176
|
-
? [
|
|
177
|
-
t.objectProperty(t.identifier('condition'), t.optionalMemberExpression(t.identifier('args'), t.identifier('condition'), false, true)),
|
|
178
|
-
]
|
|
179
|
-
: []),
|
|
180
169
|
t.objectProperty(t.identifier('orderBy'), t.tsAsExpression(t.optionalMemberExpression(t.identifier('args'), t.identifier('orderBy'), false, true), t.tsUnionType([
|
|
181
170
|
t.tsArrayType(t.tsStringKeyword()),
|
|
182
171
|
t.tsUndefinedKeyword(),
|
|
@@ -195,9 +184,6 @@ export function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
195
184
|
t.stringLiteral(whereTypeName),
|
|
196
185
|
t.stringLiteral(orderByTypeName),
|
|
197
186
|
t.identifier('connectionFieldsMap'),
|
|
198
|
-
...(conditionTypeName
|
|
199
|
-
? [t.stringLiteral(conditionTypeName)]
|
|
200
|
-
: []),
|
|
201
187
|
];
|
|
202
188
|
classBody.push(createClassMethod('findMany', createTypeParam(selectTypeName), [implParam], retType(sRef()), buildMethodBody('buildFindManyDocument', bodyArgs, 'query', typeName, pluralQueryName)));
|
|
203
189
|
}
|
|
@@ -206,9 +192,6 @@ export function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
206
192
|
const findFirstTypeArgs = [
|
|
207
193
|
(sel) => sel,
|
|
208
194
|
() => t.tsTypeReference(t.identifier(whereTypeName)),
|
|
209
|
-
...(conditionTypeName
|
|
210
|
-
? [() => t.tsTypeReference(t.identifier(conditionTypeName))]
|
|
211
|
-
: []),
|
|
212
195
|
];
|
|
213
196
|
const argsType = (sel) => t.tsTypeReference(t.identifier('FindFirstArgs'), t.tsTypeParameterInstantiation(findFirstTypeArgs.map(fn => fn(sel))));
|
|
214
197
|
const retType = (sel) => t.tsTypeAnnotation(t.tsTypeReference(t.identifier('QueryBuilder'), t.tsTypeParameterInstantiation([
|
|
@@ -230,11 +213,6 @@ export function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
230
213
|
const selectExpr = t.memberExpression(t.identifier('args'), t.identifier('select'));
|
|
231
214
|
const findFirstObjProps = [
|
|
232
215
|
t.objectProperty(t.identifier('where'), t.optionalMemberExpression(t.identifier('args'), t.identifier('where'), false, true)),
|
|
233
|
-
...(conditionTypeName
|
|
234
|
-
? [
|
|
235
|
-
t.objectProperty(t.identifier('condition'), t.optionalMemberExpression(t.identifier('args'), t.identifier('condition'), false, true)),
|
|
236
|
-
]
|
|
237
|
-
: []),
|
|
238
216
|
];
|
|
239
217
|
const bodyArgs = [
|
|
240
218
|
t.stringLiteral(typeName),
|
|
@@ -243,9 +221,6 @@ export function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
243
221
|
t.objectExpression(findFirstObjProps),
|
|
244
222
|
t.stringLiteral(whereTypeName),
|
|
245
223
|
t.identifier('connectionFieldsMap'),
|
|
246
|
-
...(conditionTypeName
|
|
247
|
-
? [t.stringLiteral(conditionTypeName)]
|
|
248
|
-
: []),
|
|
249
224
|
];
|
|
250
225
|
classBody.push(createClassMethod('findFirst', createTypeParam(selectTypeName), [implParam], retType(sRef()), buildMethodBody('buildFindFirstDocument', bodyArgs, 'query', typeName, pluralQueryName)));
|
|
251
226
|
}
|
|
@@ -574,6 +549,6 @@ export function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
574
549
|
tableName: table.name,
|
|
575
550
|
};
|
|
576
551
|
}
|
|
577
|
-
export function generateAllModelFiles(tables, useSharedTypes
|
|
578
|
-
return tables.map((table) => generateModelFile(table, useSharedTypes,
|
|
552
|
+
export function generateAllModelFiles(tables, useSharedTypes) {
|
|
553
|
+
return tables.map((table) => generateModelFile(table, useSharedTypes, undefined, tables));
|
|
579
554
|
}
|
|
@@ -150,10 +150,9 @@ export interface PageInfo {
|
|
|
150
150
|
/**
|
|
151
151
|
* Arguments for findMany operations
|
|
152
152
|
*/
|
|
153
|
-
export interface FindManyArgs<TSelect, TWhere,
|
|
153
|
+
export interface FindManyArgs<TSelect, TWhere, TOrderBy> {
|
|
154
154
|
select?: TSelect;
|
|
155
155
|
where?: TWhere;
|
|
156
|
-
condition?: TCondition;
|
|
157
156
|
orderBy?: TOrderBy[];
|
|
158
157
|
first?: number;
|
|
159
158
|
last?: number;
|
|
@@ -164,10 +163,9 @@ export interface FindManyArgs<TSelect, TWhere, TCondition, TOrderBy> {
|
|
|
164
163
|
/**
|
|
165
164
|
* Arguments for findFirst/findUnique operations
|
|
166
165
|
*/
|
|
167
|
-
export interface FindFirstArgs<TSelect, TWhere
|
|
166
|
+
export interface FindFirstArgs<TSelect, TWhere> {
|
|
168
167
|
select?: TSelect;
|
|
169
168
|
where?: TWhere;
|
|
170
|
-
condition?: TCondition;
|
|
171
169
|
}
|
|
172
170
|
/**
|
|
173
171
|
* Arguments for create operations
|