@constructive-io/graphql-codegen 4.2.0 → 4.4.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 (31) hide show
  1. package/core/codegen/cli/custom-command-generator.js +15 -4
  2. package/core/codegen/cli/executor-generator.d.ts +6 -2
  3. package/core/codegen/cli/executor-generator.js +48 -12
  4. package/core/codegen/cli/index.d.ts +10 -2
  5. package/core/codegen/cli/index.js +31 -4
  6. package/core/codegen/cli/table-command-generator.d.ts +3 -1
  7. package/core/codegen/cli/table-command-generator.js +50 -5
  8. package/core/codegen/cli/utils-generator.d.ts +17 -0
  9. package/core/codegen/cli/utils-generator.js +29 -0
  10. package/core/codegen/orm/client-generator.d.ts +3 -1
  11. package/core/codegen/orm/client-generator.js +7 -1
  12. package/core/codegen/orm/index.js +1 -1
  13. package/core/codegen/templates/cli-entry.ts +33 -0
  14. package/core/codegen/templates/node-fetch.ts +162 -0
  15. package/core/generate.js +21 -2
  16. package/esm/core/codegen/cli/custom-command-generator.js +15 -4
  17. package/esm/core/codegen/cli/executor-generator.d.ts +6 -2
  18. package/esm/core/codegen/cli/executor-generator.js +48 -12
  19. package/esm/core/codegen/cli/index.d.ts +10 -2
  20. package/esm/core/codegen/cli/index.js +31 -5
  21. package/esm/core/codegen/cli/table-command-generator.d.ts +3 -1
  22. package/esm/core/codegen/cli/table-command-generator.js +50 -5
  23. package/esm/core/codegen/cli/utils-generator.d.ts +17 -0
  24. package/esm/core/codegen/cli/utils-generator.js +27 -0
  25. package/esm/core/codegen/orm/client-generator.d.ts +3 -1
  26. package/esm/core/codegen/orm/client-generator.js +7 -1
  27. package/esm/core/codegen/orm/index.js +1 -1
  28. package/esm/core/generate.js +21 -2
  29. package/esm/types/config.d.ts +26 -0
  30. package/package.json +10 -10
  31. package/types/config.d.ts +26 -0
@@ -75,7 +75,7 @@ function createImportDeclaration(moduleSpecifier, namedImports, typeOnly = false
75
75
  /**
76
76
  * Generate the main index.ts with createClient factory
77
77
  */
78
- export function generateCreateClientFile(tables, hasCustomQueries, hasCustomMutations) {
78
+ export function generateCreateClientFile(tables, hasCustomQueries, hasCustomMutations, options) {
79
79
  const statements = [];
80
80
  // Add imports
81
81
  // Import OrmClient (value) and OrmClientConfig (type) separately
@@ -117,6 +117,12 @@ export function generateCreateClientFile(tables, hasCustomQueries, hasCustomMuta
117
117
  statements.push(t.exportAllDeclaration(t.stringLiteral('./select-types')));
118
118
  // Re-export all models
119
119
  statements.push(t.exportAllDeclaration(t.stringLiteral('./models')));
120
+ // Re-export NodeHttpAdapter when enabled (for use in any Node.js application)
121
+ if (options?.nodeHttpAdapter) {
122
+ statements.push(t.exportNamedDeclaration(null, [
123
+ t.exportSpecifier(t.identifier('NodeHttpAdapter'), t.identifier('NodeHttpAdapter')),
124
+ ], t.stringLiteral('./node-fetch')));
125
+ }
120
126
  // Re-export custom operations
121
127
  if (hasCustomQueries) {
122
128
  statements.push(t.exportNamedDeclaration(null, [
@@ -87,7 +87,7 @@ export function generateOrm(options) {
87
87
  const typesBarrel = generateTypesBarrel(useSharedTypes);
88
88
  files.push({ path: typesBarrel.fileName, content: typesBarrel.content });
89
89
  // 7. Generate main index.ts with createClient
90
- const indexFile = generateCreateClientFile(tables, hasCustomQueries, hasCustomMutations);
90
+ const indexFile = generateCreateClientFile(tables, hasCustomQueries, hasCustomMutations, { nodeHttpAdapter: !!options.config.nodeHttpAdapter });
91
91
  files.push({ path: indexFile.fileName, content: indexFile.content });
92
92
  return {
93
93
  files,
@@ -34,6 +34,9 @@ export async function generate(options = {}, internalOptions) {
34
34
  const runReactQuery = config.reactQuery ?? false;
35
35
  const runCli = internalOptions?.skipCli ? false : !!config.cli;
36
36
  const runOrm = runReactQuery || !!config.cli || (options.orm !== undefined ? !!options.orm : false);
37
+ // Auto-enable nodeHttpAdapter when CLI is enabled, unless explicitly set to false
38
+ const useNodeHttpAdapter = options.nodeHttpAdapter === true ||
39
+ (runCli && options.nodeHttpAdapter !== false);
37
40
  if (!options.schemaOnly && !runReactQuery && !runOrm && !runCli) {
38
41
  return {
39
42
  success: false,
@@ -167,13 +170,22 @@ export async function generate(options = {}, internalOptions) {
167
170
  mutations: customOperations.mutations,
168
171
  typeRegistry: customOperations.typeRegistry,
169
172
  },
170
- config,
173
+ config: { ...config, nodeHttpAdapter: useNodeHttpAdapter },
171
174
  sharedTypesPath: bothEnabled ? '..' : undefined,
172
175
  });
173
176
  filesToWrite.push(...files.map((file) => ({
174
177
  ...file,
175
178
  path: path.posix.join('orm', file.path),
176
179
  })));
180
+ // Generate NodeHttpAdapter in ORM output when enabled
181
+ if (useNodeHttpAdapter) {
182
+ const { generateNodeFetchFile } = await import('./codegen/cli/utils-generator');
183
+ const nodeFetchFile = generateNodeFetchFile();
184
+ filesToWrite.push({
185
+ path: path.posix.join('orm', nodeFetchFile.fileName),
186
+ content: nodeFetchFile.content,
187
+ });
188
+ }
177
189
  }
178
190
  // Generate CLI commands
179
191
  if (runCli) {
@@ -184,7 +196,7 @@ export async function generate(options = {}, internalOptions) {
184
196
  queries: customOperations.queries,
185
197
  mutations: customOperations.mutations,
186
198
  },
187
- config,
199
+ config: { ...config, nodeHttpAdapter: useNodeHttpAdapter },
188
200
  });
189
201
  filesToWrite.push(...files.map((file) => ({
190
202
  path: path.posix.join('cli', file.fileName),
@@ -510,10 +522,17 @@ export async function generateMulti(options) {
510
522
  if (useUnifiedCli && cliTargets.length > 0 && !dryRun) {
511
523
  const cliConfig = typeof unifiedCli === 'object' ? unifiedCli : {};
512
524
  const toolName = cliConfig.toolName ?? 'app';
525
+ // Auto-enable nodeHttpAdapter for unified CLI unless explicitly disabled
526
+ // Check first target config for explicit nodeHttpAdapter setting
527
+ const firstTargetConfig = configs[names[0]];
528
+ const multiNodeHttpAdapter = firstTargetConfig?.nodeHttpAdapter === true ||
529
+ (firstTargetConfig?.nodeHttpAdapter !== false);
513
530
  const { files } = generateMultiTargetCli({
514
531
  toolName,
515
532
  builtinNames: cliConfig.builtinNames,
516
533
  targets: cliTargets,
534
+ nodeHttpAdapter: multiNodeHttpAdapter,
535
+ entryPoint: cliConfig.entryPoint,
517
536
  });
518
537
  const cliFilesToWrite = files.map((file) => ({
519
538
  path: path.posix.join('cli', file.fileName),
@@ -169,6 +169,14 @@ export interface CliConfig {
169
169
  * context -> 'context' (renamed to 'env' on collision)
170
170
  */
171
171
  builtinNames?: BuiltinNames;
172
+ /**
173
+ * Generate a runnable index.ts entry point for the CLI.
174
+ * When true, generates an index.ts that imports the command map,
175
+ * handles --version and --tty flags, and starts the inquirerer CLI.
176
+ * Useful for projects that want a ready-to-run CLI without a custom entry point.
177
+ * @default false
178
+ */
179
+ entryPoint?: boolean;
172
180
  }
173
181
  /**
174
182
  * Target configuration for graphql-codegen
@@ -278,6 +286,24 @@ export interface GraphQLSDKConfigTarget {
278
286
  * @default false
279
287
  */
280
288
  orm?: boolean;
289
+ /**
290
+ * Enable NodeHttpAdapter generation for Node.js applications.
291
+ * When true, generates a node-fetch.ts with NodeHttpAdapter (implements GraphQLAdapter)
292
+ * using node:http/node:https for requests, enabling local development
293
+ * with subdomain-based routing (e.g. auth.localhost:3000).
294
+ * No global patching — the adapter is passed to createClient via the adapter option.
295
+ *
296
+ * When CLI generation is enabled (`cli: true`), this is auto-enabled unless
297
+ * explicitly set to `false`.
298
+ *
299
+ * Can also be used standalone with the ORM client for any Node.js application:
300
+ * ```ts
301
+ * import { NodeHttpAdapter } from './orm/node-fetch';
302
+ * const db = createClient({ adapter: new NodeHttpAdapter(endpoint, headers) });
303
+ * ```
304
+ * @default false
305
+ */
306
+ nodeHttpAdapter?: boolean;
281
307
  /**
282
308
  * Whether to generate React Query hooks
283
309
  * When enabled, generates React Query hooks to {output}/hooks
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/graphql-codegen",
3
- "version": "4.2.0",
3
+ "version": "4.4.0",
4
4
  "description": "GraphQL SDK generator for Constructive databases with React Query hooks",
5
5
  "keywords": [
6
6
  "graphql",
@@ -56,24 +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-types": "^3.0.0",
59
+ "@constructive-io/graphql-types": "^3.1.0",
60
60
  "@inquirerer/utils": "^3.2.3",
61
- "@pgpmjs/core": "^6.1.0",
61
+ "@pgpmjs/core": "^6.2.0",
62
62
  "ajv": "^8.17.1",
63
63
  "deepmerge": "^4.3.1",
64
64
  "find-and-require-package-json": "^0.9.0",
65
- "gql-ast": "^3.0.0",
66
- "graphile-schema": "^1.1.1",
65
+ "gql-ast": "^3.1.0",
66
+ "graphile-schema": "^1.2.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
71
  "komoji": "^0.8.0",
72
72
  "oxfmt": "^0.26.0",
73
- "pg-cache": "^3.0.0",
74
- "pg-env": "^1.4.0",
75
- "pgsql-client": "^3.1.0",
76
- "pgsql-seed": "^2.1.0",
73
+ "pg-cache": "^3.1.0",
74
+ "pg-env": "^1.5.0",
75
+ "pgsql-client": "^3.2.0",
76
+ "pgsql-seed": "^2.2.0",
77
77
  "undici": "^7.19.0"
78
78
  },
79
79
  "peerDependencies": {
@@ -100,5 +100,5 @@
100
100
  "tsx": "^4.21.0",
101
101
  "typescript": "^5.9.3"
102
102
  },
103
- "gitHead": "b4e199d40e7495f25bafb6e8d318e731bd19b32c"
103
+ "gitHead": "2ce4c3c62998a3c57eb04bfb67ce47bb9490f384"
104
104
  }
package/types/config.d.ts CHANGED
@@ -169,6 +169,14 @@ export interface CliConfig {
169
169
  * context -> 'context' (renamed to 'env' on collision)
170
170
  */
171
171
  builtinNames?: BuiltinNames;
172
+ /**
173
+ * Generate a runnable index.ts entry point for the CLI.
174
+ * When true, generates an index.ts that imports the command map,
175
+ * handles --version and --tty flags, and starts the inquirerer CLI.
176
+ * Useful for projects that want a ready-to-run CLI without a custom entry point.
177
+ * @default false
178
+ */
179
+ entryPoint?: boolean;
172
180
  }
173
181
  /**
174
182
  * Target configuration for graphql-codegen
@@ -278,6 +286,24 @@ export interface GraphQLSDKConfigTarget {
278
286
  * @default false
279
287
  */
280
288
  orm?: boolean;
289
+ /**
290
+ * Enable NodeHttpAdapter generation for Node.js applications.
291
+ * When true, generates a node-fetch.ts with NodeHttpAdapter (implements GraphQLAdapter)
292
+ * using node:http/node:https for requests, enabling local development
293
+ * with subdomain-based routing (e.g. auth.localhost:3000).
294
+ * No global patching — the adapter is passed to createClient via the adapter option.
295
+ *
296
+ * When CLI generation is enabled (`cli: true`), this is auto-enabled unless
297
+ * explicitly set to `false`.
298
+ *
299
+ * Can also be used standalone with the ORM client for any Node.js application:
300
+ * ```ts
301
+ * import { NodeHttpAdapter } from './orm/node-fetch';
302
+ * const db = createClient({ adapter: new NodeHttpAdapter(endpoint, headers) });
303
+ * ```
304
+ * @default false
305
+ */
306
+ nodeHttpAdapter?: boolean;
281
307
  /**
282
308
  * Whether to generate React Query hooks
283
309
  * When enabled, generates React Query hooks to {output}/hooks