@constructive-io/graphql-codegen 4.24.4 → 4.25.0

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.
Files changed (36) hide show
  1. package/core/codegen/cli/docs-generator.d.ts +2 -4
  2. package/core/codegen/cli/docs-generator.js +74 -472
  3. package/core/codegen/cli/index.d.ts +2 -2
  4. package/core/codegen/cli/index.js +1 -3
  5. package/core/codegen/cli/table-command-generator.js +165 -16
  6. package/core/codegen/docs-utils.d.ts +0 -6
  7. package/core/codegen/docs-utils.js +3 -4
  8. package/core/codegen/hooks-docs-generator.d.ts +1 -2
  9. package/core/codegen/hooks-docs-generator.js +0 -113
  10. package/core/codegen/orm/docs-generator.d.ts +1 -2
  11. package/core/codegen/orm/docs-generator.js +0 -126
  12. package/core/codegen/target-docs-generator.d.ts +1 -2
  13. package/core/codegen/target-docs-generator.js +0 -13
  14. package/core/codegen/templates/cli-utils.ts +117 -0
  15. package/core/codegen/utils.d.ts +2 -2
  16. package/core/codegen/utils.js +2 -2
  17. package/core/generate.js +0 -26
  18. package/esm/core/codegen/cli/docs-generator.d.ts +2 -4
  19. package/esm/core/codegen/cli/docs-generator.js +75 -471
  20. package/esm/core/codegen/cli/index.d.ts +2 -2
  21. package/esm/core/codegen/cli/index.js +1 -1
  22. package/esm/core/codegen/cli/table-command-generator.js +166 -17
  23. package/esm/core/codegen/docs-utils.d.ts +0 -6
  24. package/esm/core/codegen/docs-utils.js +3 -4
  25. package/esm/core/codegen/hooks-docs-generator.d.ts +1 -2
  26. package/esm/core/codegen/hooks-docs-generator.js +2 -114
  27. package/esm/core/codegen/orm/docs-generator.d.ts +1 -2
  28. package/esm/core/codegen/orm/docs-generator.js +1 -126
  29. package/esm/core/codegen/target-docs-generator.d.ts +1 -2
  30. package/esm/core/codegen/target-docs-generator.js +0 -12
  31. package/esm/core/codegen/utils.d.ts +2 -2
  32. package/esm/core/codegen/utils.js +2 -2
  33. package/esm/core/generate.js +4 -30
  34. package/esm/types/config.d.ts +1 -8
  35. package/package.json +9 -9
  36. package/types/config.d.ts +1 -8
@@ -187,6 +187,123 @@ export function unflattenDotNotation(
187
187
  * @param paths - Comma-separated dot-notation field paths (e.g. 'clientMutationId,result.accessToken')
188
188
  * @returns The nested select object for the ORM
189
189
  */
190
+ /**
191
+ * Parse a CLI flag as an integer.
192
+ * Handles minimist delivering numbers or strings depending on the input.
193
+ * Returns undefined when the flag is missing or not a valid number.
194
+ */
195
+ export function parseIntFlag(
196
+ argv: Record<string, unknown>,
197
+ name: string,
198
+ ): number | undefined {
199
+ const val = argv[name];
200
+ if (typeof val === 'number') return val;
201
+ if (typeof val === 'string') {
202
+ const n = parseInt(val, 10);
203
+ return isNaN(n) ? undefined : n;
204
+ }
205
+ return undefined;
206
+ }
207
+
208
+ /**
209
+ * Parse a CLI flag as a string.
210
+ * Returns undefined when the flag is missing or not a string.
211
+ */
212
+ export function parseStringFlag(
213
+ argv: Record<string, unknown>,
214
+ name: string,
215
+ ): string | undefined {
216
+ const val = argv[name];
217
+ return typeof val === 'string' ? val : undefined;
218
+ }
219
+
220
+ /**
221
+ * Parse --orderBy flag as a comma-separated list of enum values.
222
+ * e.g. --orderBy NAME_ASC,CREATED_AT_DESC → ['NAME_ASC', 'CREATED_AT_DESC']
223
+ */
224
+ export function parseOrderByFlag(
225
+ argv: Record<string, unknown>,
226
+ ): string[] | undefined {
227
+ const val = argv.orderBy;
228
+ return typeof val === 'string' ? val.split(',') : undefined;
229
+ }
230
+
231
+ /**
232
+ * Parse --fields flag into a select object, falling back to a default.
233
+ * e.g. --fields id,name → { id: true, name: true }
234
+ */
235
+ export function parseSelectFlag(
236
+ argv: Record<string, unknown>,
237
+ defaultSelect: Record<string, unknown>,
238
+ ): Record<string, unknown> {
239
+ const fields = argv.fields;
240
+ return typeof fields === 'string'
241
+ ? buildSelectFromPaths(fields)
242
+ : defaultSelect;
243
+ }
244
+
245
+ /**
246
+ * Build the full findManyArgs object from CLI argv.
247
+ * Parses all pagination, filtering, ordering, and field selection flags
248
+ * in one call. Accepts an optional `extraWhere` to merge with dot-notation
249
+ * --where flags (used by the search handler to inject search clauses).
250
+ *
251
+ * @example
252
+ * const findManyArgs = parseFindManyArgs(argv, { id: true, name: true });
253
+ * const result = await client.user.findMany(findManyArgs).execute();
254
+ */
255
+ export function parseFindManyArgs(
256
+ argv: Record<string, unknown>,
257
+ defaultSelect: Record<string, unknown>,
258
+ extraWhere?: Record<string, unknown>,
259
+ ): Record<string, unknown> {
260
+ const limit = parseIntFlag(argv, 'limit');
261
+ const last = parseIntFlag(argv, 'last');
262
+ const offset = parseIntFlag(argv, 'offset');
263
+ const after = parseStringFlag(argv, 'after');
264
+ const before = parseStringFlag(argv, 'before');
265
+ const select = parseSelectFlag(argv, defaultSelect);
266
+ const parsed = unflattenDotNotation(argv);
267
+ const where = parsed.where ?? extraWhere
268
+ ? { ...(extraWhere ?? {}), ...((parsed.where as Record<string, unknown>) ?? {}) }
269
+ : undefined;
270
+ const condition = parsed.condition;
271
+ const orderBy = parseOrderByFlag(argv);
272
+
273
+ return {
274
+ select,
275
+ ...(limit !== undefined ? { first: limit } : {}),
276
+ ...(after !== undefined ? { after } : {}),
277
+ ...(last !== undefined ? { last } : {}),
278
+ ...(before !== undefined ? { before } : {}),
279
+ ...(offset !== undefined ? { offset } : {}),
280
+ ...(where !== undefined ? { where } : {}),
281
+ ...(condition !== undefined ? { condition } : {}),
282
+ ...(orderBy !== undefined ? { orderBy } : {}),
283
+ };
284
+ }
285
+
286
+ /**
287
+ * Build findFirst args from CLI argv.
288
+ * Like parseFindManyArgs but only includes select, where, and condition
289
+ * (no pagination flags — findFirst returns the first matching record).
290
+ */
291
+ export function parseFindFirstArgs(
292
+ argv: Record<string, unknown>,
293
+ defaultSelect: Record<string, unknown>,
294
+ ): Record<string, unknown> {
295
+ const select = parseSelectFlag(argv, defaultSelect);
296
+ const parsed = unflattenDotNotation(argv);
297
+ const where = parsed.where;
298
+ const condition = parsed.condition;
299
+
300
+ return {
301
+ select,
302
+ ...(where !== undefined ? { where } : {}),
303
+ ...(condition !== undefined ? { condition } : {}),
304
+ };
305
+ }
306
+
190
307
  export function buildSelectFromPaths(
191
308
  paths: string,
192
309
  ): Record<string, unknown> {
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Codegen utilities - naming conventions, type mapping, and helpers
3
3
  */
4
- import { lcFirst, toCamelCase, toPascalCase, toScreamingSnake, ucFirst } from 'inflekt';
4
+ import { lcFirst, toCamelCase, toConstantCase, toPascalCase, ucFirst } from 'inflekt';
5
5
  import type { Field, FieldType, Table, TypeRegistry } from '../../types/schema';
6
- export { lcFirst, toCamelCase, toPascalCase, toScreamingSnake, ucFirst };
6
+ export { lcFirst, toCamelCase, toPascalCase, toConstantCase, ucFirst };
7
7
  export interface TableNames {
8
8
  /** PascalCase singular (e.g., "Car") */
9
9
  typeName: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ucFirst = exports.toScreamingSnake = exports.toPascalCase = exports.toCamelCase = exports.lcFirst = void 0;
3
+ exports.ucFirst = exports.toConstantCase = exports.toPascalCase = exports.toCamelCase = exports.lcFirst = void 0;
4
4
  exports.getTableNames = getTableNames;
5
5
  exports.getListQueryHookName = getListQueryHookName;
6
6
  exports.getSingleQueryHookName = getSingleQueryHookName;
@@ -45,8 +45,8 @@ exports.indent = indent;
45
45
  const inflekt_1 = require("inflekt");
46
46
  Object.defineProperty(exports, "lcFirst", { enumerable: true, get: function () { return inflekt_1.lcFirst; } });
47
47
  Object.defineProperty(exports, "toCamelCase", { enumerable: true, get: function () { return inflekt_1.toCamelCase; } });
48
+ Object.defineProperty(exports, "toConstantCase", { enumerable: true, get: function () { return inflekt_1.toConstantCase; } });
48
49
  Object.defineProperty(exports, "toPascalCase", { enumerable: true, get: function () { return inflekt_1.toPascalCase; } });
49
- Object.defineProperty(exports, "toScreamingSnake", { enumerable: true, get: function () { return inflekt_1.toScreamingSnake; } });
50
50
  Object.defineProperty(exports, "ucFirst", { enumerable: true, get: function () { return inflekt_1.ucFirst; } });
51
51
  const scalars_1 = require("./scalars");
52
52
  /**
package/core/generate.js CHANGED
@@ -274,7 +274,6 @@ async function generate(options = {}, internalOptions) {
274
274
  ...(customOperations.queries ?? []),
275
275
  ...(customOperations.mutations ?? []),
276
276
  ];
277
- const allMcpTools = [];
278
277
  const targetName = internalOptions?.targetName ?? 'default';
279
278
  const skillsToWrite = [];
280
279
  if (runOrm) {
@@ -286,9 +285,6 @@ async function generate(options = {}, internalOptions) {
286
285
  const agents = (0, docs_generator_2.generateOrmAgentsDocs)(tables, allCustomOps);
287
286
  filesToWrite.push({ path: node_path_1.default.posix.join('orm', agents.fileName), content: agents.content });
288
287
  }
289
- if (docsConfig.mcp) {
290
- allMcpTools.push(...(0, docs_generator_2.getOrmMcpTools)(tables, allCustomOps));
291
- }
292
288
  if (docsConfig.skills) {
293
289
  for (const skill of (0, docs_generator_2.generateOrmSkills)(tables, allCustomOps, targetName, customOperations.typeRegistry)) {
294
290
  skillsToWrite.push({ path: skill.fileName, content: skill.content });
@@ -304,9 +300,6 @@ async function generate(options = {}, internalOptions) {
304
300
  const agents = (0, hooks_docs_generator_1.generateHooksAgentsDocs)(tables, allCustomOps);
305
301
  filesToWrite.push({ path: node_path_1.default.posix.join('hooks', agents.fileName), content: agents.content });
306
302
  }
307
- if (docsConfig.mcp) {
308
- allMcpTools.push(...(0, hooks_docs_generator_1.getHooksMcpTools)(tables, allCustomOps));
309
- }
310
303
  if (docsConfig.skills) {
311
304
  for (const skill of (0, hooks_docs_generator_1.generateHooksSkills)(tables, allCustomOps, targetName, customOperations.typeRegistry)) {
312
305
  skillsToWrite.push({ path: skill.fileName, content: skill.content });
@@ -325,23 +318,12 @@ async function generate(options = {}, internalOptions) {
325
318
  const agents = (0, docs_generator_1.generateAgentsDocs)(tables, allCustomOps, toolName, customOperations.typeRegistry);
326
319
  filesToWrite.push({ path: node_path_1.default.posix.join('cli', agents.fileName), content: agents.content });
327
320
  }
328
- if (docsConfig.mcp) {
329
- allMcpTools.push(...(0, docs_generator_1.getCliMcpTools)(tables, allCustomOps, toolName, customOperations.typeRegistry));
330
- }
331
321
  if (docsConfig.skills) {
332
322
  for (const skill of (0, docs_generator_1.generateSkills)(tables, allCustomOps, toolName, targetName, customOperations.typeRegistry)) {
333
323
  skillsToWrite.push({ path: skill.fileName, content: skill.content });
334
324
  }
335
325
  }
336
326
  }
337
- // Generate combined mcp.json at output root
338
- if (docsConfig.mcp && allMcpTools.length > 0) {
339
- const mcpName = typeof config.cli === 'object' && config.cli?.toolName
340
- ? config.cli.toolName
341
- : 'graphql-sdk';
342
- const mcpFile = (0, target_docs_generator_1.generateCombinedMcpConfig)(allMcpTools, mcpName);
343
- filesToWrite.push({ path: mcpFile.fileName, content: mcpFile.content });
344
- }
345
327
  // Generate per-target README at output root
346
328
  if (docsConfig.readme) {
347
329
  const targetReadme = (0, target_docs_generator_1.generateTargetReadme)({
@@ -644,7 +626,6 @@ async function generateMulti(options) {
644
626
  isAuthTarget: t.isAuthTarget,
645
627
  })),
646
628
  };
647
- const allMcpTools = [];
648
629
  if (docsConfig.readme) {
649
630
  const readme = (0, docs_generator_1.generateMultiTargetReadme)(docsInput);
650
631
  cliFilesToWrite.push({ path: node_path_1.default.posix.join('cli', readme.fileName), content: readme.content });
@@ -653,13 +634,6 @@ async function generateMulti(options) {
653
634
  const agents = (0, docs_generator_1.generateMultiTargetAgentsDocs)(docsInput);
654
635
  cliFilesToWrite.push({ path: node_path_1.default.posix.join('cli', agents.fileName), content: agents.content });
655
636
  }
656
- if (docsConfig.mcp) {
657
- allMcpTools.push(...(0, docs_generator_1.getMultiTargetCliMcpTools)(docsInput));
658
- }
659
- if (docsConfig.mcp && allMcpTools.length > 0) {
660
- const mcpFile = (0, target_docs_generator_1.generateCombinedMcpConfig)(allMcpTools, toolName);
661
- cliFilesToWrite.push({ path: node_path_1.default.posix.join('cli', mcpFile.fileName), content: mcpFile.content });
662
- }
663
637
  const { writeGeneratedFiles: writeFiles } = await Promise.resolve().then(() => __importStar(require('./output')));
664
638
  await writeFiles(cliFilesToWrite, '.', [], { pruneStaleFiles: false });
665
639
  if (docsConfig.skills) {
@@ -1,10 +1,9 @@
1
1
  import type { Table, Operation, TypeRegistry } from '../../../types/schema';
2
- import type { GeneratedDocFile, McpTool } from '../docs-utils';
2
+ import type { GeneratedDocFile } from '../docs-utils';
3
3
  export { resolveDocsConfig } from '../docs-utils';
4
- export type { GeneratedDocFile, McpTool } from '../docs-utils';
4
+ export type { GeneratedDocFile } from '../docs-utils';
5
5
  export declare function generateReadme(tables: Table[], customOperations: Operation[], toolName: string, registry?: TypeRegistry): GeneratedDocFile;
6
6
  export declare function generateAgentsDocs(tables: Table[], customOperations: Operation[], toolName: string, _registry?: TypeRegistry): GeneratedDocFile;
7
- export declare function getCliMcpTools(tables: Table[], customOperations: Operation[], toolName: string, registry?: TypeRegistry): McpTool[];
8
7
  export declare function generateSkills(tables: Table[], customOperations: Operation[], toolName: string, targetName: string, registry?: TypeRegistry): GeneratedDocFile[];
9
8
  export interface MultiTargetDocsInput {
10
9
  toolName: string;
@@ -24,5 +23,4 @@ export interface MultiTargetDocsInput {
24
23
  }
25
24
  export declare function generateMultiTargetReadme(input: MultiTargetDocsInput): GeneratedDocFile;
26
25
  export declare function generateMultiTargetAgentsDocs(input: MultiTargetDocsInput): GeneratedDocFile;
27
- export declare function getMultiTargetCliMcpTools(input: MultiTargetDocsInput): McpTool[];
28
26
  export declare function generateMultiTargetSkills(input: MultiTargetDocsInput): GeneratedDocFile[];