Skip to content

fix(codegen): preserve db.pgpm when merging CLI args with file config#718

Open
pyramation wants to merge 1 commit intomainfrom
devin/1770970373-fix-codegen-schemas
Open

fix(codegen): preserve db.pgpm when merging CLI args with file config#718
pyramation wants to merge 1 commit intomainfrom
devin/1770970373-fix-codegen-schemas

Conversation

@pyramation
Copy link
Contributor

fix(codegen): preserve db.pgpm when merging CLI args with file config

Summary

When using the CLI (cnc codegen or standalone graphql-codegen) with a config file containing db.pgpm, the buildGenerateOptions function was dropping the pgpm config during the flatten/rebuild cycle:

  1. seedArgvFromConfig flattens db → extracts only schemas/apiNames, drops pgpm, config, keepDb
  2. buildGenerateOptions rebuilds db with only {schemas, apiNames}
  3. { ...fileConfig, ...withDb } overwrites fileConfig.db entirely with the incomplete db

This caused pgpm-based configs to silently fall back to database mode, connecting to whatever database the environment points to instead of creating an ephemeral PGPM deployment.

Changes:

  • buildGenerateOptions: deep-merges db from file config with CLI-derived db so pgpm, keepDb, config are preserved
  • buildDbConfig: filters undefined values from the CLI db object so they don't overwrite file config values
  • Multi-target CLI path (cli/index.ts): same deep-merge fix applied

Review & Testing Checklist for Human

  • Verify this fixes the reported issue: The user reported that schemas is ignored when using pgpm source in constructive-db's sdk/constructive-sdk. The script (generate-sdk.ts) calls generate() directly and does NOT go through the CLI path fixed here. Please confirm whether the issue reproduces via cnc codegen (CLI with config file) or pnpm generate (direct script)—this fix only addresses the CLI path.
  • Test with pgpm config file: Run cnc codegen in a directory with a graphql-sdk.config.ts that has db.pgpm and db.schemas — verify the pgpm module path is preserved and the correct ephemeral database is used.
  • Test schema filtering end-to-end: With schemas: ['constructive_public'] in the config, verify that only constructive_public objects appear in the generated schema (not all 12+ schemas).
  • Naming conflict: The actions_public.table_grant (function) vs metaschema_public.table_grant (table) PostGraphile v5 resource naming conflict is a separate issue that exists when both schemas are in the list. This PR does not address that conflict.

Notes

  • Build passes (pnpm build)
  • Could not test end-to-end (requires pgpm + Docker + PostgreSQL)
  • If the direct generate() script path also has the issue, the root cause may be elsewhere (possibly in PostGraphile v5's handling of makePgService schemas)

Requested by: @pyramation
Link to Devin run

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
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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.

1 participant