Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 19 additions & 77 deletions graphql/codegen/src/core/codegen/cli/executor-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,9 @@ function createImportDeclaration(
return decl;
}

export interface ExecutorOptions {
/** Enable NodeHttpAdapter for *.localhost subdomain routing */
nodeHttpAdapter?: boolean;
}

export function generateExecutorFile(toolName: string, options?: ExecutorOptions): GeneratedFile {
export function generateExecutorFile(toolName: string): GeneratedFile {
const statements: t.Statement[] = [];

// Import NodeHttpAdapter for *.localhost subdomain routing
if (options?.nodeHttpAdapter) {
statements.push(
createImportDeclaration('./node-fetch', ['NodeHttpAdapter']),
);
}

statements.push(
createImportDeclaration('appstash', ['createConfigStore']),
);
Expand Down Expand Up @@ -215,39 +203,20 @@ export function generateExecutorFile(toolName: string, options?: ExecutorOptions
]),
),

// Build createClient config — use NodeHttpAdapter for *.localhost endpoints
...(options?.nodeHttpAdapter
? [
t.returnStatement(
t.callExpression(t.identifier('createClient'), [
t.objectExpression([
t.objectProperty(
t.identifier('adapter'),
t.newExpression(t.identifier('NodeHttpAdapter'), [
t.memberExpression(t.identifier('ctx'), t.identifier('endpoint')),
t.identifier('headers'),
]),
),
]),
]),
t.returnStatement(
t.callExpression(t.identifier('createClient'), [
t.objectExpression([
t.objectProperty(
t.identifier('endpoint'),
t.memberExpression(t.identifier('ctx'), t.identifier('endpoint')),
),
]
: [
t.returnStatement(
t.callExpression(t.identifier('createClient'), [
t.objectExpression([
t.objectProperty(
t.identifier('endpoint'),
t.memberExpression(t.identifier('ctx'), t.identifier('endpoint')),
),
t.objectProperty(
t.identifier('headers'),
t.identifier('headers'),
),
]),
]),
t.objectProperty(
t.identifier('headers'),
t.identifier('headers'),
),
]),
]),
),
]);

const getClientFunc = t.functionDeclaration(
Expand All @@ -269,17 +238,9 @@ export function generateExecutorFile(toolName: string, options?: ExecutorOptions
export function generateMultiTargetExecutorFile(
toolName: string,
targets: MultiTargetExecutorInput[],
options?: ExecutorOptions,
): GeneratedFile {
const statements: t.Statement[] = [];

// Import NodeHttpAdapter for *.localhost subdomain routing
if (options?.nodeHttpAdapter) {
statements.push(
createImportDeclaration('./node-fetch', ['NodeHttpAdapter']),
);
}

statements.push(
createImportDeclaration('appstash', ['createConfigStore']),
);
Expand Down Expand Up @@ -538,33 +499,14 @@ export function generateMultiTargetExecutorFile(
),
]),
),
// Build createClient config — use NodeHttpAdapter for *.localhost endpoints
...(options?.nodeHttpAdapter
? [
t.returnStatement(
t.callExpression(t.identifier('createFn'), [
t.objectExpression([
t.objectProperty(
t.identifier('adapter'),
t.newExpression(t.identifier('NodeHttpAdapter'), [
t.identifier('endpoint'),
t.identifier('headers'),
]),
),
]),
]),
),
]
: [
t.returnStatement(
t.callExpression(t.identifier('createFn'), [
t.objectExpression([
t.objectProperty(t.identifier('endpoint'), t.identifier('endpoint')),
t.objectProperty(t.identifier('headers'), t.identifier('headers')),
]),
]),
),
t.returnStatement(
t.callExpression(t.identifier('createFn'), [
t.objectExpression([
t.objectProperty(t.identifier('endpoint'), t.identifier('endpoint')),
t.objectProperty(t.identifier('headers'), t.identifier('headers')),
]),
]),
),
]);

const getClientFunc = t.functionDeclaration(
Expand Down
25 changes: 3 additions & 22 deletions graphql/codegen/src/core/codegen/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
generateMultiTargetContextCommand,
} from './infra-generator';
import { generateTableCommand } from './table-command-generator';
import { generateUtilsFile, generateNodeFetchFile, generateEntryPointFile, generateEmbedderFile } from './utils-generator';
import { generateUtilsFile, generateEntryPointFile, generateEmbedderFile } from './utils-generator';

export interface GenerateCliOptions {
tables: Table[];
Expand Down Expand Up @@ -48,12 +48,7 @@ export function generateCli(options: GenerateCliOptions): GenerateCliResult {
? cliConfig.toolName
: 'app';

// Use top-level nodeHttpAdapter from config (auto-enabled for CLI by generate.ts)
const useNodeHttpAdapter = !!config.nodeHttpAdapter;

const executorFile = generateExecutorFile(toolName, {
nodeHttpAdapter: useNodeHttpAdapter,
});
const executorFile = generateExecutorFile(toolName);
files.push(executorFile);

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

// Generate node HTTP adapter if configured (for *.localhost subdomain routing)
if (useNodeHttpAdapter) {
files.push(generateNodeFetchFile());
}

const contextFile = generateContextCommand(toolName);
files.push(contextFile);

Expand Down Expand Up @@ -139,8 +129,6 @@ export interface GenerateMultiTargetCliOptions {
toolName: string;
builtinNames?: BuiltinNames;
targets: MultiTargetCliTarget[];
/** Enable NodeHttpAdapter for *.localhost subdomain routing */
nodeHttpAdapter?: boolean;
/** Generate a runnable index.ts entry point */
entryPoint?: boolean;
}
Expand Down Expand Up @@ -180,9 +168,7 @@ export function generateMultiTargetCli(
endpoint: t.endpoint,
ormImportPath: t.ormImportPath,
}));
const executorFile = generateMultiTargetExecutorFile(toolName, executorInputs, {
nodeHttpAdapter: !!options.nodeHttpAdapter,
});
const executorFile = generateMultiTargetExecutorFile(toolName, executorInputs);
files.push(executorFile);

const utilsFile = generateUtilsFile();
Expand All @@ -198,11 +184,6 @@ export function generateMultiTargetCli(
files.push(generateEmbedderFile());
}

// Generate node HTTP adapter if configured (for *.localhost subdomain routing)
if (options.nodeHttpAdapter) {
files.push(generateNodeFetchFile());
}

const contextFile = generateMultiTargetContextCommand(
toolName,
builtinNames.context,
Expand Down
17 changes: 0 additions & 17 deletions graphql/codegen/src/core/codegen/cli/utils-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,6 @@ export function generateUtilsFile(): GeneratedFile {
};
}

/**
* Generate a node-fetch.ts file with NodeHttpAdapter for CLI.
*
* Provides a GraphQLAdapter implementation using node:http/node:https
* instead of the Fetch API. This cleanly handles *.localhost subdomain
* routing (DNS resolution + Host header) without any global patching.
*/
export function generateNodeFetchFile(): GeneratedFile {
return {
fileName: 'node-fetch.ts',
content: readTemplateFile(
'node-fetch.ts',
'Node HTTP adapter for localhost subdomain routing',
),
};
}

/**
* Generate an index.ts entry point file for the CLI.
*
Expand Down
1 change: 0 additions & 1 deletion graphql/codegen/src/core/codegen/orm/client-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export function generateCreateClientFile(
tables: Table[],
hasCustomQueries: boolean,
hasCustomMutations: boolean,
options?: { nodeHttpAdapter?: boolean },
): GeneratedClientFile {
const statements: t.Statement[] = [];

Expand Down
1 change: 0 additions & 1 deletion graphql/codegen/src/core/codegen/orm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ export function generateOrm(options: GenerateOrmOptions): GenerateOrmResult {
tables,
hasCustomQueries,
hasCustomMutations,
{ nodeHttpAdapter: !!options.config.nodeHttpAdapter },
);
files.push({ path: indexFile.fileName, content: indexFile.content });

Expand Down
Loading
Loading