fix(codegen): preserve db.pgpm when merging CLI args with file config#718
Open
pyramation wants to merge 1 commit intomainfrom
Open
fix(codegen): preserve db.pgpm when merging CLI args with file config#718pyramation wants to merge 1 commit intomainfrom
pyramation wants to merge 1 commit intomainfrom
Conversation
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
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(codegen): preserve db.pgpm when merging CLI args with file config
Summary
When using the CLI (
cnc codegenor standalonegraphql-codegen) with a config file containingdb.pgpm, thebuildGenerateOptionsfunction was dropping thepgpmconfig during the flatten/rebuild cycle:seedArgvFromConfigflattensdb→ extracts onlyschemas/apiNames, dropspgpm,config,keepDbbuildGenerateOptionsrebuildsdbwith only{schemas, apiNames}{ ...fileConfig, ...withDb }overwritesfileConfig.dbentirely with the incompletedbThis 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-mergesdbfrom file config with CLI-deriveddbsopgpm,keepDb,configare preservedbuildDbConfig: filters undefined values from the CLIdbobject so they don't overwrite file config valuescli/index.ts): same deep-merge fix appliedReview & Testing Checklist for Human
schemasis ignored when using pgpm source in constructive-db'ssdk/constructive-sdk. The script (generate-sdk.ts) callsgenerate()directly and does NOT go through the CLI path fixed here. Please confirm whether the issue reproduces viacnc codegen(CLI with config file) orpnpm generate(direct script)—this fix only addresses the CLI path.cnc codegenin a directory with agraphql-sdk.config.tsthat hasdb.pgpmanddb.schemas— verify the pgpm module path is preserved and the correct ephemeral database is used.schemas: ['constructive_public']in the config, verify that onlyconstructive_publicobjects appear in the generated schema (not all 12+ schemas).actions_public.table_grant(function) vsmetaschema_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
pnpm build)generate()script path also has the issue, the root cause may be elsewhere (possibly in PostGraphile v5's handling ofmakePgServiceschemas)Requested by: @pyramation
Link to Devin run