@constructive-io/graphql-codegen 4.0.1 → 4.1.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 (97) hide show
  1. package/cli/handler.d.ts +13 -0
  2. package/cli/handler.js +74 -0
  3. package/cli/index.js +11 -60
  4. package/cli/shared.d.ts +1 -1
  5. package/cli/shared.js +2 -5
  6. package/core/codegen/barrel.d.ts +1 -0
  7. package/core/codegen/barrel.js +5 -2
  8. package/core/codegen/cli/arg-mapper.d.ts +4 -0
  9. package/core/codegen/cli/arg-mapper.js +117 -0
  10. package/core/codegen/cli/command-map-generator.d.ts +16 -0
  11. package/core/codegen/cli/command-map-generator.js +338 -0
  12. package/core/codegen/cli/custom-command-generator.d.ts +8 -0
  13. package/core/codegen/cli/custom-command-generator.js +155 -0
  14. package/core/codegen/cli/docs-generator.d.ts +26 -0
  15. package/core/codegen/cli/docs-generator.js +1399 -0
  16. package/core/codegen/cli/executor-generator.d.ts +11 -0
  17. package/core/codegen/cli/executor-generator.js +217 -0
  18. package/core/codegen/cli/index.d.ts +53 -0
  19. package/core/codegen/cli/index.js +153 -0
  20. package/core/codegen/cli/infra-generator.d.ts +9 -0
  21. package/core/codegen/cli/infra-generator.js +1195 -0
  22. package/core/codegen/cli/table-command-generator.d.ts +7 -0
  23. package/core/codegen/cli/table-command-generator.js +323 -0
  24. package/core/codegen/docs-utils.d.ts +30 -0
  25. package/core/codegen/docs-utils.js +122 -0
  26. package/core/codegen/hooks-docs-generator.d.ts +6 -0
  27. package/core/codegen/hooks-docs-generator.js +468 -0
  28. package/core/codegen/orm/docs-generator.d.ts +6 -0
  29. package/core/codegen/orm/docs-generator.js +416 -0
  30. package/core/codegen/target-docs-generator.d.ts +20 -0
  31. package/core/codegen/target-docs-generator.js +110 -0
  32. package/core/database/index.d.ts +0 -12
  33. package/core/database/index.js +2 -19
  34. package/core/generate.d.ts +34 -2
  35. package/core/generate.js +453 -12
  36. package/core/index.d.ts +0 -2
  37. package/core/index.js +0 -2
  38. package/core/introspect/source/database.js +2 -2
  39. package/core/introspect/source/pgpm-module.js +2 -2
  40. package/core/output/index.d.ts +1 -1
  41. package/core/output/index.js +1 -2
  42. package/core/output/writer.d.ts +0 -10
  43. package/core/output/writer.js +0 -31
  44. package/esm/cli/handler.d.ts +13 -0
  45. package/esm/cli/handler.js +71 -0
  46. package/esm/cli/index.js +11 -60
  47. package/esm/cli/shared.d.ts +1 -1
  48. package/esm/cli/shared.js +2 -5
  49. package/esm/core/codegen/barrel.d.ts +1 -0
  50. package/esm/core/codegen/barrel.js +5 -2
  51. package/esm/core/codegen/cli/arg-mapper.d.ts +4 -0
  52. package/esm/core/codegen/cli/arg-mapper.js +80 -0
  53. package/esm/core/codegen/cli/command-map-generator.d.ts +16 -0
  54. package/esm/core/codegen/cli/command-map-generator.js +301 -0
  55. package/esm/core/codegen/cli/custom-command-generator.d.ts +8 -0
  56. package/esm/core/codegen/cli/custom-command-generator.js +119 -0
  57. package/esm/core/codegen/cli/docs-generator.d.ts +26 -0
  58. package/esm/core/codegen/cli/docs-generator.js +1387 -0
  59. package/esm/core/codegen/cli/executor-generator.d.ts +11 -0
  60. package/esm/core/codegen/cli/executor-generator.js +180 -0
  61. package/esm/core/codegen/cli/index.d.ts +53 -0
  62. package/esm/core/codegen/cli/index.js +128 -0
  63. package/esm/core/codegen/cli/infra-generator.d.ts +9 -0
  64. package/esm/core/codegen/cli/infra-generator.js +1156 -0
  65. package/esm/core/codegen/cli/table-command-generator.d.ts +7 -0
  66. package/esm/core/codegen/cli/table-command-generator.js +287 -0
  67. package/esm/core/codegen/docs-utils.d.ts +30 -0
  68. package/esm/core/codegen/docs-utils.js +112 -0
  69. package/esm/core/codegen/hooks-docs-generator.d.ts +6 -0
  70. package/esm/core/codegen/hooks-docs-generator.js +462 -0
  71. package/esm/core/codegen/orm/docs-generator.d.ts +6 -0
  72. package/esm/core/codegen/orm/docs-generator.js +410 -0
  73. package/esm/core/codegen/target-docs-generator.d.ts +20 -0
  74. package/esm/core/codegen/target-docs-generator.js +105 -0
  75. package/esm/core/database/index.d.ts +0 -12
  76. package/esm/core/database/index.js +1 -17
  77. package/esm/core/generate.d.ts +34 -2
  78. package/esm/core/generate.js +417 -12
  79. package/esm/core/index.d.ts +0 -2
  80. package/esm/core/index.js +0 -2
  81. package/esm/core/introspect/source/database.js +2 -2
  82. package/esm/core/introspect/source/pgpm-module.js +2 -2
  83. package/esm/core/output/index.d.ts +1 -1
  84. package/esm/core/output/index.js +1 -1
  85. package/esm/core/output/writer.d.ts +0 -10
  86. package/esm/core/output/writer.js +0 -30
  87. package/esm/generators/index.d.ts +0 -3
  88. package/esm/generators/index.js +0 -3
  89. package/esm/index.d.ts +4 -3
  90. package/esm/index.js +4 -2
  91. package/esm/types/config.d.ts +78 -0
  92. package/generators/index.d.ts +0 -3
  93. package/generators/index.js +0 -3
  94. package/index.d.ts +4 -3
  95. package/index.js +7 -2
  96. package/package.json +8 -7
  97. package/types/config.d.ts +78 -0
@@ -112,6 +112,64 @@ export interface DbConfig {
112
112
  */
113
113
  keepDb?: boolean;
114
114
  }
115
+ /**
116
+ * Documentation generation options
117
+ * Controls which doc formats are generated alongside code for each generator target.
118
+ * Applied at the top level and affects all enabled generators (ORM, React Query, CLI).
119
+ */
120
+ export interface DocsConfig {
121
+ /**
122
+ * Generate README.md — human-readable overview with setup, commands, examples
123
+ * @default true
124
+ */
125
+ readme?: boolean;
126
+ /**
127
+ * Generate AGENTS.md — structured markdown optimized for LLM consumption
128
+ * Includes: tool definitions, exact signatures, input/output schemas,
129
+ * workflow recipes, error handling, and machine-parseable sections
130
+ * @default true
131
+ */
132
+ agents?: boolean;
133
+ /**
134
+ * Generate mcp.json — MCP (Model Context Protocol) tool definitions
135
+ * Each CLI command becomes a tool with typed inputSchema (JSON Schema)
136
+ * Ready to plug into any MCP-compatible agent
137
+ * @default false
138
+ */
139
+ mcp?: boolean;
140
+ /**
141
+ * Generate skills/ directory — per-command .md skill files
142
+ * Each command gets its own skill file with description, usage, and examples
143
+ * Compatible with Devin and similar agent skill systems
144
+ * @default false
145
+ */
146
+ skills?: boolean;
147
+ }
148
+ /**
149
+ * Infrastructure command name overrides for collision handling.
150
+ * When a target name collides with a default infra command name,
151
+ * the infra command is auto-renamed. These allow user overrides.
152
+ */
153
+ export interface BuiltinNames {
154
+ auth?: string;
155
+ context?: string;
156
+ }
157
+ /**
158
+ * CLI generation configuration
159
+ */
160
+ export interface CliConfig {
161
+ /**
162
+ * Tool name for appstash config storage (e.g., 'myapp' stores at ~/.myapp/)
163
+ * @default derived from output directory name
164
+ */
165
+ toolName?: string;
166
+ /**
167
+ * Override infra command names (for collision handling)
168
+ * Defaults: auth -> 'auth' (renamed to 'credentials' on collision),
169
+ * context -> 'context' (renamed to 'env' on collision)
170
+ */
171
+ builtinNames?: BuiltinNames;
172
+ }
115
173
  /**
116
174
  * Target configuration for graphql-codegen
117
175
  * Represents a single schema source and output destination.
@@ -130,6 +188,12 @@ export interface GraphQLSDKConfigTarget {
130
188
  * Path to GraphQL schema file (.graphql) for file-based generation
131
189
  */
132
190
  schemaFile?: string;
191
+ /**
192
+ * Path to a directory of .graphql schema files for multi-target generation.
193
+ * Each *.graphql file becomes its own target, named by the filename (without extension).
194
+ * e.g. schemas/app.graphql + schemas/admin.graphql → targets "app" and "admin"
195
+ */
196
+ schemaDir?: string;
133
197
  /**
134
198
  * Database configuration for direct database introspection or PGPM module
135
199
  * Use db.schemas or db.apiNames to specify which schemas to introspect
@@ -221,6 +285,20 @@ export interface GraphQLSDKConfigTarget {
221
285
  * @default false
222
286
  */
223
287
  reactQuery?: boolean;
288
+ /**
289
+ * CLI generation configuration
290
+ * When enabled, generates inquirerer-based CLI commands to {output}/cli
291
+ * Requires appstash for config storage and inquirerer for prompts
292
+ */
293
+ cli?: CliConfig | boolean;
294
+ /**
295
+ * Documentation generation options
296
+ * Controls which doc formats are generated alongside code for each generator target.
297
+ * Applied globally to all enabled generators (ORM, React Query, CLI).
298
+ * Set to `true` to enable all formats, or configure individually.
299
+ * @default { readme: true, agents: true, mcp: false, skills: false }
300
+ */
301
+ docs?: DocsConfig | boolean;
224
302
  /**
225
303
  * Query key generation configuration
226
304
  * Controls how query keys are structured for cache management
@@ -1,8 +1,5 @@
1
1
  /**
2
2
  * Query and mutation generator exports
3
- *
4
- * @deprecated Legacy v4 generators — use v5 ORM codegen pipeline instead.
5
- * These are retained for backward compatibility with existing v4 consumers.
6
3
  */
7
4
  export { convertToSelectionOptions, getAvailableRelations, isRelationalField, validateFieldSelection, } from './field-selector';
8
5
  export { buildCount, buildFindOne, buildSelect, cleanTableToMetaObject, createASTQueryBuilder, generateIntrospectionSchema, toCamelCasePlural, toOrderByTypeName, } from './select';
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
3
  * Query and mutation generator exports
4
- *
5
- * @deprecated Legacy v4 generators — use v5 ORM codegen pipeline instead.
6
- * These are retained for backward compatibility with existing v4 consumers.
7
4
  */
8
5
  Object.defineProperty(exports, "__esModule", { value: true });
9
6
  exports.buildPostGraphileUpdate = exports.buildPostGraphileDelete = exports.buildPostGraphileCreate = exports.toOrderByTypeName = exports.toCamelCasePlural = exports.generateIntrospectionSchema = exports.createASTQueryBuilder = exports.cleanTableToMetaObject = exports.buildSelect = exports.buildFindOne = exports.buildCount = exports.validateFieldSelection = exports.isRelationalField = exports.getAvailableRelations = exports.convertToSelectionOptions = void 0;
package/index.d.ts CHANGED
@@ -10,10 +10,11 @@ export * from './core';
10
10
  export * from './generators';
11
11
  export * from './client';
12
12
  export { defineConfig } from './types/config';
13
- export type { GenerateOptions, GenerateResult } from './core/generate';
14
- export { generate } from './core/generate';
13
+ export type { GenerateOptions, GenerateResult, GenerateMultiOptions, GenerateMultiResult } from './core/generate';
14
+ export { generate, generateMulti, expandApiNamesToMultiTarget, expandSchemaDirToMultiTarget } from './core/generate';
15
15
  export { findConfigFile, loadConfigFile } from './core/config';
16
+ export { runCodegenHandler } from './cli/handler';
16
17
  export type { CodegenAnswers } from './cli/shared';
17
18
  export { buildDbConfig, buildGenerateOptions, camelizeArgv, codegenQuestions, filterDefined, flattenDbFields, hasResolvedCodegenSource, hyphenateKeys, normalizeCodegenListOptions, printResult, seedArgvFromConfig, splitCommas, } from './cli/shared';
18
19
  export type { BuildSchemaFromDatabaseOptions, BuildSchemaFromDatabaseResult, } from './core/database';
19
- export { buildSchemaFromDatabase, buildSchemaSDLFromDatabase, } from './core/database';
20
+ export { buildSchemaFromDatabase } from './core/database';
package/index.js CHANGED
@@ -21,7 +21,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
21
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
22
  };
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.buildSchemaSDLFromDatabase = exports.buildSchemaFromDatabase = exports.splitCommas = exports.seedArgvFromConfig = exports.printResult = exports.normalizeCodegenListOptions = exports.hyphenateKeys = exports.hasResolvedCodegenSource = exports.flattenDbFields = exports.filterDefined = exports.codegenQuestions = exports.camelizeArgv = exports.buildGenerateOptions = exports.buildDbConfig = exports.loadConfigFile = exports.findConfigFile = exports.generate = exports.defineConfig = void 0;
24
+ exports.buildSchemaFromDatabase = exports.splitCommas = exports.seedArgvFromConfig = exports.printResult = exports.normalizeCodegenListOptions = exports.hyphenateKeys = exports.hasResolvedCodegenSource = exports.flattenDbFields = exports.filterDefined = exports.codegenQuestions = exports.camelizeArgv = exports.buildGenerateOptions = exports.buildDbConfig = exports.runCodegenHandler = exports.loadConfigFile = exports.findConfigFile = exports.expandSchemaDirToMultiTarget = exports.expandApiNamesToMultiTarget = exports.generateMulti = exports.generate = exports.defineConfig = void 0;
25
25
  // Core types
26
26
  __exportStar(require("./types"), exports);
27
27
  // Core query building
@@ -35,10 +35,16 @@ var config_1 = require("./types/config");
35
35
  Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return config_1.defineConfig; } });
36
36
  var generate_1 = require("./core/generate");
37
37
  Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return generate_1.generate; } });
38
+ Object.defineProperty(exports, "generateMulti", { enumerable: true, get: function () { return generate_1.generateMulti; } });
39
+ Object.defineProperty(exports, "expandApiNamesToMultiTarget", { enumerable: true, get: function () { return generate_1.expandApiNamesToMultiTarget; } });
40
+ Object.defineProperty(exports, "expandSchemaDirToMultiTarget", { enumerable: true, get: function () { return generate_1.expandSchemaDirToMultiTarget; } });
38
41
  // Config utilities
39
42
  var config_2 = require("./core/config");
40
43
  Object.defineProperty(exports, "findConfigFile", { enumerable: true, get: function () { return config_2.findConfigFile; } });
41
44
  Object.defineProperty(exports, "loadConfigFile", { enumerable: true, get: function () { return config_2.loadConfigFile; } });
45
+ // CLI shared utilities (for packages/cli to import)
46
+ var handler_1 = require("./cli/handler");
47
+ Object.defineProperty(exports, "runCodegenHandler", { enumerable: true, get: function () { return handler_1.runCodegenHandler; } });
42
48
  var shared_1 = require("./cli/shared");
43
49
  Object.defineProperty(exports, "buildDbConfig", { enumerable: true, get: function () { return shared_1.buildDbConfig; } });
44
50
  Object.defineProperty(exports, "buildGenerateOptions", { enumerable: true, get: function () { return shared_1.buildGenerateOptions; } });
@@ -54,4 +60,3 @@ Object.defineProperty(exports, "seedArgvFromConfig", { enumerable: true, get: fu
54
60
  Object.defineProperty(exports, "splitCommas", { enumerable: true, get: function () { return shared_1.splitCommas; } });
55
61
  var database_1 = require("./core/database");
56
62
  Object.defineProperty(exports, "buildSchemaFromDatabase", { enumerable: true, get: function () { return database_1.buildSchemaFromDatabase; } });
57
- Object.defineProperty(exports, "buildSchemaSDLFromDatabase", { enumerable: true, get: function () { return database_1.buildSchemaSDLFromDatabase; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/graphql-codegen",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "description": "GraphQL SDK generator for Constructive databases with React Query hooks",
5
5
  "keywords": [
6
6
  "graphql",
@@ -42,7 +42,7 @@
42
42
  "lint": "eslint . --fix",
43
43
  "fmt": "oxfmt --write .",
44
44
  "fmt:check": "oxfmt --check .",
45
- "test": "jest --passWithNoTests",
45
+ "test": "jest",
46
46
  "test:watch": "jest --watch",
47
47
  "example:codegen:sdk": "tsx src/cli/index.ts --config examples/multi-target.config.ts --react-query",
48
48
  "example:codegen:orm": "tsx src/cli/index.ts --config examples/multi-target.config.ts --orm",
@@ -56,23 +56,24 @@
56
56
  "@0no-co/graphql.web": "^1.1.2",
57
57
  "@babel/generator": "^7.28.6",
58
58
  "@babel/types": "^7.28.6",
59
- "@constructive-io/graphql-server": "^4.0.1",
60
59
  "@constructive-io/graphql-types": "^3.0.0",
61
60
  "@inquirerer/utils": "^3.2.3",
62
- "@pgpmjs/core": "^6.0.0",
61
+ "@pgpmjs/core": "^6.1.0",
63
62
  "ajv": "^8.17.1",
64
63
  "deepmerge": "^4.3.1",
65
64
  "find-and-require-package-json": "^0.9.0",
66
65
  "gql-ast": "^3.0.0",
66
+ "graphile-schema": "^1.1.0",
67
67
  "graphql": "^16.9.0",
68
68
  "inflekt": "^0.3.1",
69
69
  "inquirerer": "^4.4.0",
70
70
  "jiti": "^2.6.1",
71
+ "komoji": "^0.8.0",
71
72
  "oxfmt": "^0.26.0",
72
73
  "pg-cache": "^3.0.0",
73
74
  "pg-env": "^1.4.0",
74
- "pgsql-client": "^3.0.0",
75
- "pgsql-seed": "^2.0.0",
75
+ "pgsql-client": "^3.1.0",
76
+ "pgsql-seed": "^2.1.0",
76
77
  "undici": "^7.19.0"
77
78
  },
78
79
  "peerDependencies": {
@@ -99,5 +100,5 @@
99
100
  "tsx": "^4.21.0",
100
101
  "typescript": "^5.9.3"
101
102
  },
102
- "gitHead": "c05d6bd3dfa36690aefe21079042666dfae801a1"
103
+ "gitHead": "6dac0247c675de94b41038ac1e5095dc5df0c753"
103
104
  }
package/types/config.d.ts CHANGED
@@ -112,6 +112,64 @@ export interface DbConfig {
112
112
  */
113
113
  keepDb?: boolean;
114
114
  }
115
+ /**
116
+ * Documentation generation options
117
+ * Controls which doc formats are generated alongside code for each generator target.
118
+ * Applied at the top level and affects all enabled generators (ORM, React Query, CLI).
119
+ */
120
+ export interface DocsConfig {
121
+ /**
122
+ * Generate README.md — human-readable overview with setup, commands, examples
123
+ * @default true
124
+ */
125
+ readme?: boolean;
126
+ /**
127
+ * Generate AGENTS.md — structured markdown optimized for LLM consumption
128
+ * Includes: tool definitions, exact signatures, input/output schemas,
129
+ * workflow recipes, error handling, and machine-parseable sections
130
+ * @default true
131
+ */
132
+ agents?: boolean;
133
+ /**
134
+ * Generate mcp.json — MCP (Model Context Protocol) tool definitions
135
+ * Each CLI command becomes a tool with typed inputSchema (JSON Schema)
136
+ * Ready to plug into any MCP-compatible agent
137
+ * @default false
138
+ */
139
+ mcp?: boolean;
140
+ /**
141
+ * Generate skills/ directory — per-command .md skill files
142
+ * Each command gets its own skill file with description, usage, and examples
143
+ * Compatible with Devin and similar agent skill systems
144
+ * @default false
145
+ */
146
+ skills?: boolean;
147
+ }
148
+ /**
149
+ * Infrastructure command name overrides for collision handling.
150
+ * When a target name collides with a default infra command name,
151
+ * the infra command is auto-renamed. These allow user overrides.
152
+ */
153
+ export interface BuiltinNames {
154
+ auth?: string;
155
+ context?: string;
156
+ }
157
+ /**
158
+ * CLI generation configuration
159
+ */
160
+ export interface CliConfig {
161
+ /**
162
+ * Tool name for appstash config storage (e.g., 'myapp' stores at ~/.myapp/)
163
+ * @default derived from output directory name
164
+ */
165
+ toolName?: string;
166
+ /**
167
+ * Override infra command names (for collision handling)
168
+ * Defaults: auth -> 'auth' (renamed to 'credentials' on collision),
169
+ * context -> 'context' (renamed to 'env' on collision)
170
+ */
171
+ builtinNames?: BuiltinNames;
172
+ }
115
173
  /**
116
174
  * Target configuration for graphql-codegen
117
175
  * Represents a single schema source and output destination.
@@ -130,6 +188,12 @@ export interface GraphQLSDKConfigTarget {
130
188
  * Path to GraphQL schema file (.graphql) for file-based generation
131
189
  */
132
190
  schemaFile?: string;
191
+ /**
192
+ * Path to a directory of .graphql schema files for multi-target generation.
193
+ * Each *.graphql file becomes its own target, named by the filename (without extension).
194
+ * e.g. schemas/app.graphql + schemas/admin.graphql → targets "app" and "admin"
195
+ */
196
+ schemaDir?: string;
133
197
  /**
134
198
  * Database configuration for direct database introspection or PGPM module
135
199
  * Use db.schemas or db.apiNames to specify which schemas to introspect
@@ -221,6 +285,20 @@ export interface GraphQLSDKConfigTarget {
221
285
  * @default false
222
286
  */
223
287
  reactQuery?: boolean;
288
+ /**
289
+ * CLI generation configuration
290
+ * When enabled, generates inquirerer-based CLI commands to {output}/cli
291
+ * Requires appstash for config storage and inquirerer for prompts
292
+ */
293
+ cli?: CliConfig | boolean;
294
+ /**
295
+ * Documentation generation options
296
+ * Controls which doc formats are generated alongside code for each generator target.
297
+ * Applied globally to all enabled generators (ORM, React Query, CLI).
298
+ * Set to `true` to enable all formats, or configure individually.
299
+ * @default { readme: true, agents: true, mcp: false, skills: false }
300
+ */
301
+ docs?: DocsConfig | boolean;
224
302
  /**
225
303
  * Query key generation configuration
226
304
  * Controls how query keys are structured for cache management