Skip to content

Commit 5c6279f

Browse files
committed
fix(codegen): use deepmerge for CLI config merging
Replace manual spread operators with deepmerge (via mergeConfig) for merging file config with CLI options. This ensures nested objects like db.pgpm are properly deep-merged rather than overwritten. Also restores filterDefined in buildDbConfig to prevent undefined CLI values from interfering with file config during merge.
1 parent db546ec commit 5c6279f

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

graphql/codegen/src/cli/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { CLI, CLIOptions, getPackageJson, Inquirerer } from 'inquirerer';
99

1010
import { findConfigFile, loadConfigFile } from '../core/config';
1111
import { generate } from '../core/generate';
12-
import type { GraphQLSDKConfigTarget } from '../types/config';
12+
import { mergeConfig, type GraphQLSDKConfigTarget } from '../types/config';
1313
import {
1414
buildDbConfig,
1515
buildGenerateOptions,
@@ -114,10 +114,9 @@ export const commands = async (
114114
let hasError = false;
115115
for (const name of names) {
116116
console.log(`\n[${name}]`);
117-
const result = await generate({
118-
...targets[name],
119-
...cliOptions,
120-
} as GraphQLSDKConfigTarget);
117+
const result = await generate(
118+
mergeConfig(targets[name], cliOptions as GraphQLSDKConfigTarget),
119+
);
121120
printResult(result);
122121
if (!result.success) hasError = true;
123122
}

graphql/codegen/src/cli/shared.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { inflektTree } from 'inflekt/transform-keys';
99
import type { Question } from 'inquirerer';
1010

1111
import type { GenerateResult } from '../core/generate';
12-
import type { GraphQLSDKConfigTarget } from '../types/config';
12+
import { mergeConfig, type GraphQLSDKConfigTarget } from '../types/config';
1313

1414
export const splitCommas = (
1515
input: string | undefined,
@@ -202,7 +202,10 @@ export function buildDbConfig(
202202
): Record<string, unknown> {
203203
const { schemas, apiNames, ...rest } = options;
204204
if (schemas || apiNames) {
205-
return { ...rest, db: { schemas, apiNames } };
205+
return {
206+
...rest,
207+
db: filterDefined({ schemas, apiNames } as Record<string, unknown>),
208+
};
206209
}
207210
return rest;
208211
}
@@ -259,5 +262,5 @@ export function buildGenerateOptions(
259262
const camelized = camelizeArgv(answers);
260263
const normalized = normalizeCodegenListOptions(camelized);
261264
const withDb = buildDbConfig(normalized);
262-
return { ...fileConfig, ...withDb } as GraphQLSDKConfigTarget;
265+
return mergeConfig(fileConfig, withDb as GraphQLSDKConfigTarget);
263266
}

0 commit comments

Comments
 (0)