Skip to content

Commit 0e87d7a

Browse files
authored
Merge pull request #722 from constructive-io/devin/1771130267-codegen-deepmerge-config
fix(codegen): use deepmerge for CLI config merging
2 parents c05d6bd + 1eab89e commit 0e87d7a

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

graphql/codegen/src/cli/index.ts

Lines changed: 4 additions & 6 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,11 +114,9 @@ export const commands = async (
114114
let hasError = false;
115115
for (const name of names) {
116116
console.log(`\n[${name}]`);
117-
const targetConfig = { ...targets[name], ...cliOptions } as GraphQLSDKConfigTarget;
118-
if (targets[name].db && targetConfig.db) {
119-
targetConfig.db = { ...targets[name].db, ...targetConfig.db };
120-
}
121-
const result = await generate(targetConfig);
117+
const result = await generate(
118+
mergeConfig(targets[name], cliOptions as GraphQLSDKConfigTarget),
119+
);
122120
printResult(result);
123121
if (!result.success) hasError = true;
124122
}

graphql/codegen/src/cli/shared.ts

Lines changed: 2 additions & 6 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,
@@ -262,9 +262,5 @@ export function buildGenerateOptions(
262262
const camelized = camelizeArgv(answers);
263263
const normalized = normalizeCodegenListOptions(camelized);
264264
const withDb = buildDbConfig(normalized);
265-
const merged = { ...fileConfig, ...withDb } as GraphQLSDKConfigTarget;
266-
if (fileConfig.db && merged.db) {
267-
merged.db = { ...fileConfig.db, ...merged.db };
268-
}
269-
return merged;
265+
return mergeConfig(fileConfig, withDb as GraphQLSDKConfigTarget);
270266
}

0 commit comments

Comments
 (0)