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
15 changes: 15 additions & 0 deletions graphile/graphile-settings/src/plugins/conflict-detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export const ConflictDetectorPlugin: GraphileConfig.Plugin = {
// Track codecs by their GraphQL name to detect conflicts
const codecsByName = new Map<string, CodecInfo[]>();

// Get configured schemas from pgServices to only check relevant codecs
const configuredSchemas = new Set<string>();
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)
Expand All @@ -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);

Expand Down
9 changes: 5 additions & 4 deletions graphql/codegen/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 9 additions & 2 deletions graphql/codegen/src/cli/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ export function buildDbConfig(
): Record<string, unknown> {
const { schemas, apiNames, ...rest } = options;
if (schemas || apiNames) {
return { ...rest, db: { schemas, apiNames } };
return {
...rest,
db: filterDefined({ schemas, apiNames } as Record<string, unknown>),
};
}
return rest;
}
Expand Down Expand Up @@ -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;
}