@constructive-io/graphql-codegen 4.1.3 → 4.3.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 +58 -19
  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 +7 -1
  5. package/core/codegen/cli/index.js +20 -3
  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 +8 -0
  9. package/core/codegen/cli/utils-generator.js +14 -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-utils.ts +59 -2
  14. package/core/codegen/templates/node-fetch.ts +162 -0
  15. package/core/generate.js +20 -2
  16. package/esm/core/codegen/cli/custom-command-generator.js +58 -19
  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 +7 -1
  20. package/esm/core/codegen/cli/index.js +21 -4
  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 +8 -0
  24. package/esm/core/codegen/cli/utils-generator.js +13 -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 +20 -2
  29. package/esm/types/config.d.ts +18 -0
  30. package/package.json +10 -10
  31. package/types/config.d.ts +18 -0
@@ -40,3 +40,16 @@ export function generateUtilsFile() {
40
40
  content: readTemplateFile('cli-utils.ts', 'CLI utility functions for type coercion and input handling'),
41
41
  };
42
42
  }
43
+ /**
44
+ * Generate a node-fetch.ts file with NodeHttpAdapter for CLI.
45
+ *
46
+ * Provides a GraphQLAdapter implementation using node:http/node:https
47
+ * instead of the Fetch API. This cleanly handles *.localhost subdomain
48
+ * routing (DNS resolution + Host header) without any global patching.
49
+ */
50
+ export function generateNodeFetchFile() {
51
+ return {
52
+ fileName: 'node-fetch.ts',
53
+ content: readTemplateFile('node-fetch.ts', 'Node HTTP adapter for localhost subdomain routing'),
54
+ };
55
+ }
@@ -25,4 +25,6 @@ export declare function generateSelectTypesFile(): GeneratedClientFile;
25
25
  /**
26
26
  * Generate the main index.ts with createClient factory
27
27
  */
28
- export declare function generateCreateClientFile(tables: CleanTable[], hasCustomQueries: boolean, hasCustomMutations: boolean): GeneratedClientFile;
28
+ export declare function generateCreateClientFile(tables: CleanTable[], hasCustomQueries: boolean, hasCustomMutations: boolean, options?: {
29
+ nodeHttpAdapter?: boolean;
30
+ }): GeneratedClientFile;
@@ -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,16 @@ 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,
517
535
  });
518
536
  const cliFilesToWrite = files.map((file) => ({
519
537
  path: path.posix.join('cli', file.fileName),
@@ -278,6 +278,24 @@ export interface GraphQLSDKConfigTarget {
278
278
  * @default false
279
279
  */
280
280
  orm?: boolean;
281
+ /**
282
+ * Enable NodeHttpAdapter generation for Node.js applications.
283
+ * When true, generates a node-fetch.ts with NodeHttpAdapter (implements GraphQLAdapter)
284
+ * using node:http/node:https for requests, enabling local development
285
+ * with subdomain-based routing (e.g. auth.localhost:3000).
286
+ * No global patching — the adapter is passed to createClient via the adapter option.
287
+ *
288
+ * When CLI generation is enabled (`cli: true`), this is auto-enabled unless
289
+ * explicitly set to `false`.
290
+ *
291
+ * Can also be used standalone with the ORM client for any Node.js application:
292
+ * ```ts
293
+ * import { NodeHttpAdapter } from './orm/node-fetch';
294
+ * const db = createClient({ adapter: new NodeHttpAdapter(endpoint, headers) });
295
+ * ```
296
+ * @default false
297
+ */
298
+ nodeHttpAdapter?: boolean;
281
299
  /**
282
300
  * Whether to generate React Query hooks
283
301
  * 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.1.3",
3
+ "version": "4.3.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": "f80e2e5e112cab91eac53e61c5b257f4ac88efb2"
103
+ "gitHead": "b758178b808ce0bf451e86c0bd7e92079155db7c"
104
104
  }
package/types/config.d.ts CHANGED
@@ -278,6 +278,24 @@ export interface GraphQLSDKConfigTarget {
278
278
  * @default false
279
279
  */
280
280
  orm?: boolean;
281
+ /**
282
+ * Enable NodeHttpAdapter generation for Node.js applications.
283
+ * When true, generates a node-fetch.ts with NodeHttpAdapter (implements GraphQLAdapter)
284
+ * using node:http/node:https for requests, enabling local development
285
+ * with subdomain-based routing (e.g. auth.localhost:3000).
286
+ * No global patching — the adapter is passed to createClient via the adapter option.
287
+ *
288
+ * When CLI generation is enabled (`cli: true`), this is auto-enabled unless
289
+ * explicitly set to `false`.
290
+ *
291
+ * Can also be used standalone with the ORM client for any Node.js application:
292
+ * ```ts
293
+ * import { NodeHttpAdapter } from './orm/node-fetch';
294
+ * const db = createClient({ adapter: new NodeHttpAdapter(endpoint, headers) });
295
+ * ```
296
+ * @default false
297
+ */
298
+ nodeHttpAdapter?: boolean;
281
299
  /**
282
300
  * Whether to generate React Query hooks
283
301
  * When enabled, generates React Query hooks to {output}/hooks