diff --git a/graphile/graphile-settings/src/plugins/conflict-detector.ts b/graphile/graphile-settings/src/plugins/conflict-detector.ts index d829468e2..edf8bdc7a 100644 --- a/graphile/graphile-settings/src/plugins/conflict-detector.ts +++ b/graphile/graphile-settings/src/plugins/conflict-detector.ts @@ -29,6 +29,16 @@ export const ConflictDetectorPlugin: GraphileConfig.Plugin = { // Track codecs by their GraphQL name to detect conflicts const codecsByName = new Map(); + // Get configured schemas from pgServices to only check relevant codecs + const configuredSchemas = new Set(); + const pgServices = (build as any).resolvedPreset?.pgServices ?? []; + + for (const service of pgServices) { + for (const schema of service.schemas ?? ['public']) { + configuredSchemas.add(schema); + } + } + // Iterate through all codecs to find tables for (const codec of Object.values(build.input.pgRegistry.pgCodecs)) { // Skip non-table codecs (those without attributes or anonymous ones) @@ -41,6 +51,11 @@ export const ConflictDetectorPlugin: GraphileConfig.Plugin = { const schemaName = pgExtensions?.schemaName || 'unknown'; const tableName = codec.name; + // Skip codecs from schemas not in the configured list + if (configuredSchemas.size > 0 && !configuredSchemas.has(schemaName)) { + continue; + } + // Get the GraphQL name that would be generated const graphqlName = build.inflection.tableType(codec); diff --git a/graphql/codegen/src/cli/index.ts b/graphql/codegen/src/cli/index.ts index 8ab33c45a..6eda80c87 100644 --- a/graphql/codegen/src/cli/index.ts +++ b/graphql/codegen/src/cli/index.ts @@ -114,10 +114,11 @@ export const commands = async ( let hasError = false; for (const name of names) { console.log(`\n[${name}]`); - const result = await generate({ - ...targets[name], - ...cliOptions, - } as GraphQLSDKConfigTarget); + const targetConfig = { ...targets[name], ...cliOptions } as GraphQLSDKConfigTarget; + if (targets[name].db && targetConfig.db) { + targetConfig.db = { ...targets[name].db, ...targetConfig.db }; + } + const result = await generate(targetConfig); printResult(result); if (!result.success) hasError = true; } diff --git a/graphql/codegen/src/cli/shared.ts b/graphql/codegen/src/cli/shared.ts index 9b08cb8f5..d6e219aa1 100644 --- a/graphql/codegen/src/cli/shared.ts +++ b/graphql/codegen/src/cli/shared.ts @@ -202,7 +202,10 @@ export function buildDbConfig( ): Record { const { schemas, apiNames, ...rest } = options; if (schemas || apiNames) { - return { ...rest, db: { schemas, apiNames } }; + return { + ...rest, + db: filterDefined({ schemas, apiNames } as Record), + }; } return rest; } @@ -259,5 +262,9 @@ export function buildGenerateOptions( const camelized = camelizeArgv(answers); const normalized = normalizeCodegenListOptions(camelized); const withDb = buildDbConfig(normalized); - return { ...fileConfig, ...withDb } as GraphQLSDKConfigTarget; + const merged = { ...fileConfig, ...withDb } as GraphQLSDKConfigTarget; + if (fileConfig.db && merged.db) { + merged.db = { ...fileConfig.db, ...merged.db }; + } + return merged; }