@constructive-io/graphql-codegen 4.12.2 → 4.13.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/command-map-generator.d.ts +1 -0
- package/core/codegen/cli/command-map-generator.js +4 -0
- package/core/codegen/cli/config-command-generator.d.ts +11 -0
- package/core/codegen/cli/config-command-generator.js +458 -0
- package/core/codegen/cli/docs-generator.d.ts +1 -0
- package/core/codegen/cli/docs-generator.js +267 -1
- package/core/codegen/cli/helpers-generator.d.ts +15 -0
- package/core/codegen/cli/helpers-generator.js +119 -0
- package/core/codegen/cli/index.d.ts +4 -0
- package/core/codegen/cli/index.js +21 -3
- package/core/codegen/orm/index.js +3 -2
- package/core/codegen/orm/input-types-generator.d.ts +3 -1
- package/core/codegen/orm/input-types-generator.js +14 -6
- package/core/codegen/orm/model-generator.d.ts +6 -2
- package/core/codegen/orm/model-generator.js +59 -37
- package/core/codegen/templates/query-builder.ts +2 -2
- package/core/codegen/templates/select-types.ts +2 -2
- package/esm/core/codegen/cli/command-map-generator.d.ts +1 -0
- package/esm/core/codegen/cli/command-map-generator.js +4 -0
- package/esm/core/codegen/cli/config-command-generator.d.ts +11 -0
- package/esm/core/codegen/cli/config-command-generator.js +422 -0
- package/esm/core/codegen/cli/docs-generator.d.ts +1 -0
- package/esm/core/codegen/cli/docs-generator.js +267 -1
- package/esm/core/codegen/cli/helpers-generator.d.ts +15 -0
- package/esm/core/codegen/cli/helpers-generator.js +83 -0
- package/esm/core/codegen/cli/index.d.ts +4 -0
- package/esm/core/codegen/cli/index.js +18 -2
- package/esm/core/codegen/orm/index.js +3 -2
- package/esm/core/codegen/orm/input-types-generator.d.ts +3 -1
- package/esm/core/codegen/orm/input-types-generator.js +14 -6
- package/esm/core/codegen/orm/model-generator.d.ts +6 -2
- package/esm/core/codegen/orm/model-generator.js +59 -37
- package/esm/types/config.d.ts +9 -0
- package/esm/types/config.js +1 -0
- package/package.json +4 -4
- package/types/config.d.ts +9 -0
- package/types/config.js +1 -0
|
@@ -1062,9 +1062,9 @@ function buildTableCrudTypeNames(tables) {
|
|
|
1062
1062
|
/**
|
|
1063
1063
|
* Generate custom input type statements from TypeRegistry
|
|
1064
1064
|
*/
|
|
1065
|
-
function generateCustomInputTypes(typeRegistry, usedInputTypes, tableCrudTypes, comments = true) {
|
|
1065
|
+
function generateCustomInputTypes(typeRegistry, usedInputTypes, tableCrudTypes, comments = true, alreadyGeneratedTypes) {
|
|
1066
1066
|
const statements = [];
|
|
1067
|
-
const generatedTypes = new Set();
|
|
1067
|
+
const generatedTypes = new Set(alreadyGeneratedTypes ?? []);
|
|
1068
1068
|
const typesToGenerate = new Set(Array.from(usedInputTypes));
|
|
1069
1069
|
// Filter out types we've already generated (exact matches for table CRUD types only)
|
|
1070
1070
|
if (tableCrudTypes) {
|
|
@@ -1334,7 +1334,8 @@ function collectConditionExtraInputTypes(tables, typeRegistry) {
|
|
|
1334
1334
|
/**
|
|
1335
1335
|
* Generate comprehensive input-types.ts file using Babel AST
|
|
1336
1336
|
*/
|
|
1337
|
-
function generateInputTypesFile(typeRegistry, usedInputTypes, tables, usedPayloadTypes, comments = true) {
|
|
1337
|
+
function generateInputTypesFile(typeRegistry, usedInputTypes, tables, usedPayloadTypes, comments = true, options) {
|
|
1338
|
+
const conditionEnabled = options?.condition !== false;
|
|
1338
1339
|
const statements = [];
|
|
1339
1340
|
const tablesList = tables ?? [];
|
|
1340
1341
|
const hasTables = tablesList.length > 0;
|
|
@@ -1361,7 +1362,9 @@ function generateInputTypesFile(typeRegistry, usedInputTypes, tables, usedPayloa
|
|
|
1361
1362
|
// 4b. Table condition types (simple equality filter)
|
|
1362
1363
|
// Pass typeRegistry to merge plugin-injected condition fields
|
|
1363
1364
|
// (e.g., vectorEmbedding from VectorSearchPlugin)
|
|
1364
|
-
|
|
1365
|
+
if (conditionEnabled) {
|
|
1366
|
+
statements.push(...generateTableConditionTypes(tablesList, typeRegistry));
|
|
1367
|
+
}
|
|
1365
1368
|
// 5. OrderBy types
|
|
1366
1369
|
// Pass typeRegistry to merge plugin-injected orderBy values
|
|
1367
1370
|
// (e.g., EMBEDDING_DISTANCE_ASC/DESC from VectorSearchPlugin)
|
|
@@ -1375,14 +1378,19 @@ function generateInputTypesFile(typeRegistry, usedInputTypes, tables, usedPayloa
|
|
|
1375
1378
|
// 7. Custom input types from TypeRegistry
|
|
1376
1379
|
// Also include any extra types referenced by plugin-injected condition fields
|
|
1377
1380
|
const mergedUsedInputTypes = new Set(usedInputTypes);
|
|
1378
|
-
if (hasTables) {
|
|
1381
|
+
if (hasTables && conditionEnabled) {
|
|
1379
1382
|
const conditionExtraTypes = collectConditionExtraInputTypes(tablesList, typeRegistry);
|
|
1380
1383
|
for (const typeName of conditionExtraTypes) {
|
|
1381
1384
|
mergedUsedInputTypes.add(typeName);
|
|
1382
1385
|
}
|
|
1383
1386
|
}
|
|
1384
1387
|
const tableCrudTypes = tables ? buildTableCrudTypeNames(tables) : undefined;
|
|
1385
|
-
|
|
1388
|
+
// Pass customScalarTypes + enumTypes as already-generated to avoid duplicate declarations
|
|
1389
|
+
const alreadyGenerated = new Set([
|
|
1390
|
+
...customScalarTypes,
|
|
1391
|
+
...enumTypes,
|
|
1392
|
+
]);
|
|
1393
|
+
statements.push(...generateCustomInputTypes(typeRegistry, mergedUsedInputTypes, tableCrudTypes, comments, alreadyGenerated));
|
|
1386
1394
|
// 8. Payload/return types for custom operations
|
|
1387
1395
|
if (usedPayloadTypes && usedPayloadTypes.size > 0) {
|
|
1388
1396
|
const alreadyGeneratedTypes = new Set();
|
|
@@ -5,5 +5,9 @@ export interface GeneratedModelFile {
|
|
|
5
5
|
modelName: string;
|
|
6
6
|
tableName: string;
|
|
7
7
|
}
|
|
8
|
-
export declare function generateModelFile(table: CleanTable, _useSharedTypes: boolean
|
|
9
|
-
|
|
8
|
+
export declare function generateModelFile(table: CleanTable, _useSharedTypes: boolean, options?: {
|
|
9
|
+
condition?: boolean;
|
|
10
|
+
}): GeneratedModelFile;
|
|
11
|
+
export declare function generateAllModelFiles(tables: CleanTable[], useSharedTypes: boolean, options?: {
|
|
12
|
+
condition?: boolean;
|
|
13
|
+
}): GeneratedModelFile[];
|
|
@@ -102,7 +102,8 @@ function strictSelectGuard(selectTypeName) {
|
|
|
102
102
|
t.tsTypeReference(t.identifier(selectTypeName)),
|
|
103
103
|
]));
|
|
104
104
|
}
|
|
105
|
-
function generateModelFile(table, _useSharedTypes) {
|
|
105
|
+
function generateModelFile(table, _useSharedTypes, options) {
|
|
106
|
+
const conditionEnabled = options?.condition !== false;
|
|
106
107
|
const { typeName, singularName, pluralName } = (0, utils_1.getTableNames)(table);
|
|
107
108
|
const modelName = `${typeName}Model`;
|
|
108
109
|
const baseFileName = (0, utils_1.lcFirst)(typeName);
|
|
@@ -111,7 +112,7 @@ function generateModelFile(table, _useSharedTypes) {
|
|
|
111
112
|
const selectTypeName = `${typeName}Select`;
|
|
112
113
|
const relationTypeName = `${typeName}WithRelations`;
|
|
113
114
|
const whereTypeName = (0, utils_1.getFilterTypeName)(table);
|
|
114
|
-
const conditionTypeName = `${typeName}Condition
|
|
115
|
+
const conditionTypeName = conditionEnabled ? `${typeName}Condition` : undefined;
|
|
115
116
|
const orderByTypeName = (0, utils_1.getOrderByTypeName)(table);
|
|
116
117
|
const createInputTypeName = `Create${typeName}Input`;
|
|
117
118
|
const updateInputTypeName = `Update${typeName}Input`;
|
|
@@ -146,17 +147,18 @@ function generateModelFile(table, _useSharedTypes) {
|
|
|
146
147
|
'InferSelectResult',
|
|
147
148
|
'StrictSelect',
|
|
148
149
|
], true));
|
|
149
|
-
|
|
150
|
+
const inputTypeImports = [
|
|
150
151
|
typeName,
|
|
151
152
|
relationTypeName,
|
|
152
153
|
selectTypeName,
|
|
153
154
|
whereTypeName,
|
|
154
|
-
conditionTypeName,
|
|
155
|
+
...(conditionTypeName ? [conditionTypeName] : []),
|
|
155
156
|
orderByTypeName,
|
|
156
157
|
createInputTypeName,
|
|
157
158
|
updateInputTypeName,
|
|
158
159
|
patchTypeName,
|
|
159
|
-
]
|
|
160
|
+
];
|
|
161
|
+
statements.push(createImportDeclaration('../input-types', inputTypeImports, true));
|
|
160
162
|
statements.push(createImportDeclaration('../input-types', ['connectionFieldsMap']));
|
|
161
163
|
const classBody = [];
|
|
162
164
|
// Constructor
|
|
@@ -170,12 +172,15 @@ function generateModelFile(table, _useSharedTypes) {
|
|
|
170
172
|
const pkTsType = () => tsTypeFromPrimitive(pkField.tsType);
|
|
171
173
|
// ── findMany ───────────────────────────────────────────────────────────
|
|
172
174
|
{
|
|
173
|
-
const
|
|
174
|
-
sel,
|
|
175
|
-
t.tsTypeReference(t.identifier(whereTypeName)),
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
175
|
+
const findManyTypeArgs = [
|
|
176
|
+
(sel) => sel,
|
|
177
|
+
() => t.tsTypeReference(t.identifier(whereTypeName)),
|
|
178
|
+
...(conditionTypeName
|
|
179
|
+
? [() => t.tsTypeReference(t.identifier(conditionTypeName))]
|
|
180
|
+
: []),
|
|
181
|
+
() => t.tsTypeReference(t.identifier(orderByTypeName)),
|
|
182
|
+
];
|
|
183
|
+
const argsType = (sel) => t.tsTypeReference(t.identifier('FindManyArgs'), t.tsTypeParameterInstantiation(findManyTypeArgs.map(fn => fn(sel))));
|
|
179
184
|
const retType = (sel) => t.tsTypeAnnotation(t.tsTypeReference(t.identifier('QueryBuilder'), t.tsTypeParameterInstantiation([
|
|
180
185
|
t.tsTypeLiteral([
|
|
181
186
|
t.tsPropertySignature(t.identifier(pluralQueryName), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('ConnectionResult'), t.tsTypeParameterInstantiation([
|
|
@@ -193,37 +198,47 @@ function generateModelFile(table, _useSharedTypes) {
|
|
|
193
198
|
strictSelectGuard(selectTypeName),
|
|
194
199
|
]));
|
|
195
200
|
const selectExpr = t.memberExpression(t.identifier('args'), t.identifier('select'));
|
|
201
|
+
const findManyObjProps = [
|
|
202
|
+
t.objectProperty(t.identifier('where'), t.optionalMemberExpression(t.identifier('args'), t.identifier('where'), false, true)),
|
|
203
|
+
...(conditionTypeName
|
|
204
|
+
? [
|
|
205
|
+
t.objectProperty(t.identifier('condition'), t.optionalMemberExpression(t.identifier('args'), t.identifier('condition'), false, true)),
|
|
206
|
+
]
|
|
207
|
+
: []),
|
|
208
|
+
t.objectProperty(t.identifier('orderBy'), t.tsAsExpression(t.optionalMemberExpression(t.identifier('args'), t.identifier('orderBy'), false, true), t.tsUnionType([
|
|
209
|
+
t.tsArrayType(t.tsStringKeyword()),
|
|
210
|
+
t.tsUndefinedKeyword(),
|
|
211
|
+
]))),
|
|
212
|
+
t.objectProperty(t.identifier('first'), t.optionalMemberExpression(t.identifier('args'), t.identifier('first'), false, true)),
|
|
213
|
+
t.objectProperty(t.identifier('last'), t.optionalMemberExpression(t.identifier('args'), t.identifier('last'), false, true)),
|
|
214
|
+
t.objectProperty(t.identifier('after'), t.optionalMemberExpression(t.identifier('args'), t.identifier('after'), false, true)),
|
|
215
|
+
t.objectProperty(t.identifier('before'), t.optionalMemberExpression(t.identifier('args'), t.identifier('before'), false, true)),
|
|
216
|
+
t.objectProperty(t.identifier('offset'), t.optionalMemberExpression(t.identifier('args'), t.identifier('offset'), false, true)),
|
|
217
|
+
];
|
|
196
218
|
const bodyArgs = [
|
|
197
219
|
t.stringLiteral(typeName),
|
|
198
220
|
t.stringLiteral(pluralQueryName),
|
|
199
221
|
selectExpr,
|
|
200
|
-
t.objectExpression(
|
|
201
|
-
t.objectProperty(t.identifier('where'), t.optionalMemberExpression(t.identifier('args'), t.identifier('where'), false, true)),
|
|
202
|
-
t.objectProperty(t.identifier('condition'), t.optionalMemberExpression(t.identifier('args'), t.identifier('condition'), false, true)),
|
|
203
|
-
t.objectProperty(t.identifier('orderBy'), t.tsAsExpression(t.optionalMemberExpression(t.identifier('args'), t.identifier('orderBy'), false, true), t.tsUnionType([
|
|
204
|
-
t.tsArrayType(t.tsStringKeyword()),
|
|
205
|
-
t.tsUndefinedKeyword(),
|
|
206
|
-
]))),
|
|
207
|
-
t.objectProperty(t.identifier('first'), t.optionalMemberExpression(t.identifier('args'), t.identifier('first'), false, true)),
|
|
208
|
-
t.objectProperty(t.identifier('last'), t.optionalMemberExpression(t.identifier('args'), t.identifier('last'), false, true)),
|
|
209
|
-
t.objectProperty(t.identifier('after'), t.optionalMemberExpression(t.identifier('args'), t.identifier('after'), false, true)),
|
|
210
|
-
t.objectProperty(t.identifier('before'), t.optionalMemberExpression(t.identifier('args'), t.identifier('before'), false, true)),
|
|
211
|
-
t.objectProperty(t.identifier('offset'), t.optionalMemberExpression(t.identifier('args'), t.identifier('offset'), false, true)),
|
|
212
|
-
]),
|
|
222
|
+
t.objectExpression(findManyObjProps),
|
|
213
223
|
t.stringLiteral(whereTypeName),
|
|
214
224
|
t.stringLiteral(orderByTypeName),
|
|
215
225
|
t.identifier('connectionFieldsMap'),
|
|
216
|
-
|
|
226
|
+
...(conditionTypeName
|
|
227
|
+
? [t.stringLiteral(conditionTypeName)]
|
|
228
|
+
: []),
|
|
217
229
|
];
|
|
218
230
|
classBody.push(createClassMethod('findMany', createTypeParam(selectTypeName), [implParam], retType(sRef()), buildMethodBody('buildFindManyDocument', bodyArgs, 'query', typeName, pluralQueryName)));
|
|
219
231
|
}
|
|
220
232
|
// ── findFirst ──────────────────────────────────────────────────────────
|
|
221
233
|
{
|
|
222
|
-
const
|
|
223
|
-
sel,
|
|
224
|
-
t.tsTypeReference(t.identifier(whereTypeName)),
|
|
225
|
-
|
|
226
|
-
|
|
234
|
+
const findFirstTypeArgs = [
|
|
235
|
+
(sel) => sel,
|
|
236
|
+
() => t.tsTypeReference(t.identifier(whereTypeName)),
|
|
237
|
+
...(conditionTypeName
|
|
238
|
+
? [() => t.tsTypeReference(t.identifier(conditionTypeName))]
|
|
239
|
+
: []),
|
|
240
|
+
];
|
|
241
|
+
const argsType = (sel) => t.tsTypeReference(t.identifier('FindFirstArgs'), t.tsTypeParameterInstantiation(findFirstTypeArgs.map(fn => fn(sel))));
|
|
227
242
|
const retType = (sel) => t.tsTypeAnnotation(t.tsTypeReference(t.identifier('QueryBuilder'), t.tsTypeParameterInstantiation([
|
|
228
243
|
t.tsTypeLiteral([
|
|
229
244
|
t.tsPropertySignature(t.identifier(pluralQueryName), t.tsTypeAnnotation(t.tsTypeLiteral([
|
|
@@ -241,17 +256,24 @@ function generateModelFile(table, _useSharedTypes) {
|
|
|
241
256
|
strictSelectGuard(selectTypeName),
|
|
242
257
|
]));
|
|
243
258
|
const selectExpr = t.memberExpression(t.identifier('args'), t.identifier('select'));
|
|
259
|
+
const findFirstObjProps = [
|
|
260
|
+
t.objectProperty(t.identifier('where'), t.optionalMemberExpression(t.identifier('args'), t.identifier('where'), false, true)),
|
|
261
|
+
...(conditionTypeName
|
|
262
|
+
? [
|
|
263
|
+
t.objectProperty(t.identifier('condition'), t.optionalMemberExpression(t.identifier('args'), t.identifier('condition'), false, true)),
|
|
264
|
+
]
|
|
265
|
+
: []),
|
|
266
|
+
];
|
|
244
267
|
const bodyArgs = [
|
|
245
268
|
t.stringLiteral(typeName),
|
|
246
269
|
t.stringLiteral(pluralQueryName),
|
|
247
270
|
selectExpr,
|
|
248
|
-
t.objectExpression(
|
|
249
|
-
t.objectProperty(t.identifier('where'), t.optionalMemberExpression(t.identifier('args'), t.identifier('where'), false, true)),
|
|
250
|
-
t.objectProperty(t.identifier('condition'), t.optionalMemberExpression(t.identifier('args'), t.identifier('condition'), false, true)),
|
|
251
|
-
]),
|
|
271
|
+
t.objectExpression(findFirstObjProps),
|
|
252
272
|
t.stringLiteral(whereTypeName),
|
|
253
273
|
t.identifier('connectionFieldsMap'),
|
|
254
|
-
|
|
274
|
+
...(conditionTypeName
|
|
275
|
+
? [t.stringLiteral(conditionTypeName)]
|
|
276
|
+
: []),
|
|
255
277
|
];
|
|
256
278
|
classBody.push(createClassMethod('findFirst', createTypeParam(selectTypeName), [implParam], retType(sRef()), buildMethodBody('buildFindFirstDocument', bodyArgs, 'query', typeName, pluralQueryName)));
|
|
257
279
|
}
|
|
@@ -455,6 +477,6 @@ function generateModelFile(table, _useSharedTypes) {
|
|
|
455
477
|
tableName: table.name,
|
|
456
478
|
};
|
|
457
479
|
}
|
|
458
|
-
function generateAllModelFiles(tables, useSharedTypes) {
|
|
459
|
-
return tables.map((table) => generateModelFile(table, useSharedTypes));
|
|
480
|
+
function generateAllModelFiles(tables, useSharedTypes, options) {
|
|
481
|
+
return tables.map((table) => generateModelFile(table, useSharedTypes, options));
|
|
460
482
|
}
|
|
@@ -201,7 +201,7 @@ export function buildSelections(
|
|
|
201
201
|
// Document Builders
|
|
202
202
|
// ============================================================================
|
|
203
203
|
|
|
204
|
-
export function buildFindManyDocument<TSelect, TWhere, TCondition>(
|
|
204
|
+
export function buildFindManyDocument<TSelect, TWhere, TCondition = never>(
|
|
205
205
|
operationName: string,
|
|
206
206
|
queryField: string,
|
|
207
207
|
select: TSelect,
|
|
@@ -320,7 +320,7 @@ export function buildFindManyDocument<TSelect, TWhere, TCondition>(
|
|
|
320
320
|
return { document: print(document), variables };
|
|
321
321
|
}
|
|
322
322
|
|
|
323
|
-
export function buildFindFirstDocument<TSelect, TWhere, TCondition>(
|
|
323
|
+
export function buildFindFirstDocument<TSelect, TWhere, TCondition = never>(
|
|
324
324
|
operationName: string,
|
|
325
325
|
queryField: string,
|
|
326
326
|
select: TSelect,
|
|
@@ -21,7 +21,7 @@ export interface PageInfo {
|
|
|
21
21
|
endCursor?: string | null;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export interface FindManyArgs<TSelect, TWhere, TCondition, TOrderBy> {
|
|
24
|
+
export interface FindManyArgs<TSelect, TWhere, TCondition = never, TOrderBy = never> {
|
|
25
25
|
select?: TSelect;
|
|
26
26
|
where?: TWhere;
|
|
27
27
|
condition?: TCondition;
|
|
@@ -33,7 +33,7 @@ export interface FindManyArgs<TSelect, TWhere, TCondition, TOrderBy> {
|
|
|
33
33
|
offset?: number;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export interface FindFirstArgs<TSelect, TWhere, TCondition> {
|
|
36
|
+
export interface FindFirstArgs<TSelect, TWhere, TCondition = never> {
|
|
37
37
|
select?: TSelect;
|
|
38
38
|
where?: TWhere;
|
|
39
39
|
condition?: TCondition;
|
|
@@ -186,6 +186,9 @@ export function generateMultiTargetCommandMap(input) {
|
|
|
186
186
|
const authImportName = `${builtinNames.auth}Cmd`;
|
|
187
187
|
commandEntries.push({ kebab: builtinNames.auth, importName: authImportName });
|
|
188
188
|
statements.push(createImportDeclaration(`./commands/${builtinNames.auth}`, authImportName));
|
|
189
|
+
const configImportName = `${builtinNames.config}Cmd`;
|
|
190
|
+
commandEntries.push({ kebab: builtinNames.config, importName: configImportName });
|
|
191
|
+
statements.push(createImportDeclaration(`./commands/${builtinNames.config}`, configImportName));
|
|
189
192
|
for (const target of targets) {
|
|
190
193
|
for (const table of target.tables) {
|
|
191
194
|
const { singularName } = getTableNames(table);
|
|
@@ -222,6 +225,7 @@ export function generateMultiTargetCommandMap(input) {
|
|
|
222
225
|
'Commands:',
|
|
223
226
|
` ${builtinNames.context.padEnd(20)} Manage API contexts`,
|
|
224
227
|
` ${builtinNames.auth.padEnd(20)} Manage authentication`,
|
|
228
|
+
` ${builtinNames.config.padEnd(20)} Manage config key-value store`,
|
|
225
229
|
];
|
|
226
230
|
for (const target of targets) {
|
|
227
231
|
usageLines.push('');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { GeneratedFile } from './executor-generator';
|
|
2
|
+
/**
|
|
3
|
+
* Generate the config command file (get/set/list/delete for per-context vars).
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* <tool> config get <key>
|
|
7
|
+
* <tool> config set <key> <value>
|
|
8
|
+
* <tool> config list
|
|
9
|
+
* <tool> config delete <key>
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateConfigCommand(toolName: string, commandName: string): GeneratedFile;
|