Skip to content

Commit 23d1a53

Browse files
committed
refactor: remove NodeHttpAdapter in favor of @constructive-io/fetch
The ORM client's FetchAdapter already uses createFetch() from @constructive-io/fetch, which handles *.localhost DNS rewriting and Host header preservation in Node.js. The separate NodeHttpAdapter (using node:http/node:https directly) is redundant. - Remove node-fetch.ts template and all generated node-fetch.ts files - Remove generateNodeFetchFile() from utils-generator - Simplify executor generators to always use { endpoint, headers } - Remove nodeHttpAdapter config plumbing from generate.ts - Deprecate nodeHttpAdapter option in config types - Update all 4 SDK executor.ts files to use endpoint/headers The external API (createClient, getClient) is unchanged — consumers pass endpoint + headers, and FetchAdapter handles the rest.
1 parent 70f9d20 commit 23d1a53

18 files changed

Lines changed: 38 additions & 1748 deletions

File tree

graphql/codegen/src/core/codegen/cli/executor-generator.ts

Lines changed: 21 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,13 @@ function createImportDeclaration(
3131
}
3232

3333
export interface ExecutorOptions {
34-
/** Enable NodeHttpAdapter for *.localhost subdomain routing */
34+
/** @deprecated NodeHttpAdapter has been removed; createClient uses @constructive-io/fetch automatically */
3535
nodeHttpAdapter?: boolean;
3636
}
3737

38-
export function generateExecutorFile(toolName: string, options?: ExecutorOptions): GeneratedFile {
38+
export function generateExecutorFile(toolName: string, _options?: ExecutorOptions): GeneratedFile {
3939
const statements: t.Statement[] = [];
4040

41-
// Import NodeHttpAdapter for *.localhost subdomain routing
42-
if (options?.nodeHttpAdapter) {
43-
statements.push(
44-
createImportDeclaration('./node-fetch', ['NodeHttpAdapter']),
45-
);
46-
}
47-
4841
statements.push(
4942
createImportDeclaration('appstash', ['createConfigStore']),
5043
);
@@ -215,39 +208,20 @@ export function generateExecutorFile(toolName: string, options?: ExecutorOptions
215208
]),
216209
),
217210

218-
// Build createClient config — use NodeHttpAdapter for *.localhost endpoints
219-
...(options?.nodeHttpAdapter
220-
? [
221-
t.returnStatement(
222-
t.callExpression(t.identifier('createClient'), [
223-
t.objectExpression([
224-
t.objectProperty(
225-
t.identifier('adapter'),
226-
t.newExpression(t.identifier('NodeHttpAdapter'), [
227-
t.memberExpression(t.identifier('ctx'), t.identifier('endpoint')),
228-
t.identifier('headers'),
229-
]),
230-
),
231-
]),
232-
]),
211+
t.returnStatement(
212+
t.callExpression(t.identifier('createClient'), [
213+
t.objectExpression([
214+
t.objectProperty(
215+
t.identifier('endpoint'),
216+
t.memberExpression(t.identifier('ctx'), t.identifier('endpoint')),
233217
),
234-
]
235-
: [
236-
t.returnStatement(
237-
t.callExpression(t.identifier('createClient'), [
238-
t.objectExpression([
239-
t.objectProperty(
240-
t.identifier('endpoint'),
241-
t.memberExpression(t.identifier('ctx'), t.identifier('endpoint')),
242-
),
243-
t.objectProperty(
244-
t.identifier('headers'),
245-
t.identifier('headers'),
246-
),
247-
]),
248-
]),
218+
t.objectProperty(
219+
t.identifier('headers'),
220+
t.identifier('headers'),
249221
),
250222
]),
223+
]),
224+
),
251225
]);
252226

253227
const getClientFunc = t.functionDeclaration(
@@ -269,17 +243,10 @@ export function generateExecutorFile(toolName: string, options?: ExecutorOptions
269243
export function generateMultiTargetExecutorFile(
270244
toolName: string,
271245
targets: MultiTargetExecutorInput[],
272-
options?: ExecutorOptions,
246+
_options?: ExecutorOptions,
273247
): GeneratedFile {
274248
const statements: t.Statement[] = [];
275249

276-
// Import NodeHttpAdapter for *.localhost subdomain routing
277-
if (options?.nodeHttpAdapter) {
278-
statements.push(
279-
createImportDeclaration('./node-fetch', ['NodeHttpAdapter']),
280-
);
281-
}
282-
283250
statements.push(
284251
createImportDeclaration('appstash', ['createConfigStore']),
285252
);
@@ -538,33 +505,14 @@ export function generateMultiTargetExecutorFile(
538505
),
539506
]),
540507
),
541-
// Build createClient config — use NodeHttpAdapter for *.localhost endpoints
542-
...(options?.nodeHttpAdapter
543-
? [
544-
t.returnStatement(
545-
t.callExpression(t.identifier('createFn'), [
546-
t.objectExpression([
547-
t.objectProperty(
548-
t.identifier('adapter'),
549-
t.newExpression(t.identifier('NodeHttpAdapter'), [
550-
t.identifier('endpoint'),
551-
t.identifier('headers'),
552-
]),
553-
),
554-
]),
555-
]),
556-
),
557-
]
558-
: [
559-
t.returnStatement(
560-
t.callExpression(t.identifier('createFn'), [
561-
t.objectExpression([
562-
t.objectProperty(t.identifier('endpoint'), t.identifier('endpoint')),
563-
t.objectProperty(t.identifier('headers'), t.identifier('headers')),
564-
]),
565-
]),
566-
),
508+
t.returnStatement(
509+
t.callExpression(t.identifier('createFn'), [
510+
t.objectExpression([
511+
t.objectProperty(t.identifier('endpoint'), t.identifier('endpoint')),
512+
t.objectProperty(t.identifier('headers'), t.identifier('headers')),
567513
]),
514+
]),
515+
),
568516
]);
569517

570518
const getClientFunc = t.functionDeclaration(

graphql/codegen/src/core/codegen/cli/index.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
generateMultiTargetContextCommand,
1515
} from './infra-generator';
1616
import { generateTableCommand } from './table-command-generator';
17-
import { generateUtilsFile, generateNodeFetchFile, generateEntryPointFile, generateEmbedderFile } from './utils-generator';
17+
import { generateUtilsFile, generateEntryPointFile, generateEmbedderFile } from './utils-generator';
1818

1919
export interface GenerateCliOptions {
2020
tables: Table[];
@@ -48,12 +48,7 @@ export function generateCli(options: GenerateCliOptions): GenerateCliResult {
4848
? cliConfig.toolName
4949
: 'app';
5050

51-
// Use top-level nodeHttpAdapter from config (auto-enabled for CLI by generate.ts)
52-
const useNodeHttpAdapter = !!config.nodeHttpAdapter;
53-
54-
const executorFile = generateExecutorFile(toolName, {
55-
nodeHttpAdapter: useNodeHttpAdapter,
56-
});
51+
const executorFile = generateExecutorFile(toolName);
5752
files.push(executorFile);
5853

5954
const utilsFile = generateUtilsFile();
@@ -67,11 +62,6 @@ export function generateCli(options: GenerateCliOptions): GenerateCliResult {
6762
files.push(generateEmbedderFile());
6863
}
6964

70-
// Generate node HTTP adapter if configured (for *.localhost subdomain routing)
71-
if (useNodeHttpAdapter) {
72-
files.push(generateNodeFetchFile());
73-
}
74-
7565
const contextFile = generateContextCommand(toolName);
7666
files.push(contextFile);
7767

@@ -139,7 +129,7 @@ export interface GenerateMultiTargetCliOptions {
139129
toolName: string;
140130
builtinNames?: BuiltinNames;
141131
targets: MultiTargetCliTarget[];
142-
/** Enable NodeHttpAdapter for *.localhost subdomain routing */
132+
/** @deprecated NodeHttpAdapter removed; createClient uses @constructive-io/fetch */
143133
nodeHttpAdapter?: boolean;
144134
/** Generate a runnable index.ts entry point */
145135
entryPoint?: boolean;
@@ -180,9 +170,7 @@ export function generateMultiTargetCli(
180170
endpoint: t.endpoint,
181171
ormImportPath: t.ormImportPath,
182172
}));
183-
const executorFile = generateMultiTargetExecutorFile(toolName, executorInputs, {
184-
nodeHttpAdapter: !!options.nodeHttpAdapter,
185-
});
173+
const executorFile = generateMultiTargetExecutorFile(toolName, executorInputs);
186174
files.push(executorFile);
187175

188176
const utilsFile = generateUtilsFile();
@@ -198,11 +186,6 @@ export function generateMultiTargetCli(
198186
files.push(generateEmbedderFile());
199187
}
200188

201-
// Generate node HTTP adapter if configured (for *.localhost subdomain routing)
202-
if (options.nodeHttpAdapter) {
203-
files.push(generateNodeFetchFile());
204-
}
205-
206189
const contextFile = generateMultiTargetContextCommand(
207190
toolName,
208191
builtinNames.context,

graphql/codegen/src/core/codegen/cli/utils-generator.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,6 @@ export function generateUtilsFile(): GeneratedFile {
6060
};
6161
}
6262

63-
/**
64-
* Generate a node-fetch.ts file with NodeHttpAdapter for CLI.
65-
*
66-
* Provides a GraphQLAdapter implementation using node:http/node:https
67-
* instead of the Fetch API. This cleanly handles *.localhost subdomain
68-
* routing (DNS resolution + Host header) without any global patching.
69-
*/
70-
export function generateNodeFetchFile(): GeneratedFile {
71-
return {
72-
fileName: 'node-fetch.ts',
73-
content: readTemplateFile(
74-
'node-fetch.ts',
75-
'Node HTTP adapter for localhost subdomain routing',
76-
),
77-
};
78-
}
79-
8063
/**
8164
* Generate an index.ts entry point file for the CLI.
8265
*

0 commit comments

Comments
 (0)