Skip to content

Fix/codegen schema filtering#720

Open
yyyyaaa wants to merge 2 commits intomainfrom
fix/codegen-schema-filtering
Open

Fix/codegen schema filtering#720
yyyyaaa wants to merge 2 commits intomainfrom
fix/codegen-schema-filtering

Conversation

@yyyyaaa
Copy link
Contributor

@yyyyaaa yyyyaaa commented Feb 14, 2026

Summary

  • Fix PostGraphile v5 resource registry crash (Attempted to add a second resource named "table_grant") when a function and a table share the same base name across schemas.
  • Add a functionResourceName override to InflektPlugin that restores schema prefixes for functions while keeping clean, unprefixed names for tables.
  • Filter ConflictDetectorPlugin by configured pgServices.schemas to prevent false-positive warnings from unrelated schemas.

Problem

InflektPlugin._schemaPrefix currently returns '' for all schemas to give tables clean GraphQL names. However, PostGraphile’s functionResourceName also uses _schemaPrefix, which means functions lose their schema prefix too.

When a function and a table share the same base name across schemas (e.g. actions_public.table_grant() and metaschema_public.table_grant), both end up with the resource name table_grant, and PostGraphile’s flat registry throws.

Solution

Override functionResourceName in InflektPlugin to bypass our _schemaPrefix override and use PostGraphile’s default prefix logic for functions only:

Resource Schema Resource Name GraphQL Name
metaschema_public.table_grant (table) primary (schemas[0]) table_grant TableGrant
actions_public.table_grant() (function) non-primary actions_public_table_grant actionsPublicTableGrant

Functions in the primary schema still get clean names (no prefix). Functions in non-primary schemas get their schema name as a prefix, preventing collisions with same-named tables.

Test plan

  • graphile-settings builds successfully
  • graphql/codegen — 230 tests pass, 75 snapshots match
  • constructive-db/sdk/constructive-sdkpnpm run generate completes (72 tables, 82 queries, 314 mutations)
  • constructive-db/application/app — 101 tests pass (4 test suites have pre-existing TS type errors unrelated to this change)

pyramation and others added 2 commits February 13, 2026 08:22
When using the CLI (cnc codegen or graphql-codegen) with a config file
that has db.pgpm, the buildGenerateOptions function was dropping the
pgpm config during the flatten/rebuild cycle:

1. seedArgvFromConfig flattens db to extract schemas/apiNames
2. buildGenerateOptions rebuilds db with only schemas/apiNames
3. The spread { ...fileConfig, ...withDb } overwrites fileConfig.db

This caused pgpm-based configs to silently fall back to database mode,
ignoring the pgpm module path and potentially connecting to the wrong
database.

Fix:
- Deep-merge db configs in buildGenerateOptions to preserve pgpm,
  config, keepDb, and other db fields from the file config
- Apply same fix to multi-target CLI path in cli/index.ts
- Filter undefined values in buildDbConfig to prevent overwriting
  file config values with undefined CLI defaults
Add functionResourceName override to InflektPlugin to restore schema
prefixes for functions while keeping clean names for tables. Filter
ConflictDetectorPlugin by configured schemas to prevent false positives.
@yyyyaaa yyyyaaa requested a review from pyramation February 14, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants