refactor(cli): simplify arg parsing with generic transforms, remove --browser-compatible#692
Open
pyramation wants to merge 7 commits intomainfrom
Open
refactor(cli): simplify arg parsing with generic transforms, remove --browser-compatible#692pyramation wants to merge 7 commits intomainfrom
pyramation wants to merge 7 commits intomainfrom
Conversation
…-browser-compatible - Add hyphenateKeys, flattenDbFields, buildDbConfig, seedArgvFromConfig, buildGenerateOptions to shared.ts as generic reusable utilities - Replace manual cliOverrides/hasNonInteractiveArgs with prompt->camelize->generate flow - Remove deprecated --browser-compatible flag from CLI, config types, and generate - Simplify both CLI entry points (graphql/codegen/src/cli, packages/cli) - Update test mocks to match new shared utility imports
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.
refactor(cli): simplify arg parsing with generic transforms, remove --browser-compatible
Summary
Replaces the manual field-by-field CLI argument parsing in both CLI entry points with a generic transform pipeline:
seedArgvFromConfig → prompt → camelizeArgv → buildDbConfig → generate. Removes the deprecated--browser-compatibleflag entirely.Before: Each CLI file had ~3 redundant layers — manual
cliOverridesbuilt field-by-field with if-statements, ahasNonInteractiveArgsguard duplicating the same flag list, and a post-prompt field-by-field mapping intogenerate()options. All duplicated across both CLIs.After: Both CLIs share generic utilities from
shared.ts:hyphenateKeys/camelizeArgv— bidirectional key transforms (camelCase ↔ hyphen-case)flattenDbFields/buildDbConfig— flatten/nest thedb.schemas/db.apiNamesstructureseedArgvFromConfig— merge config file values into argv (config as defaults, CLI flags override)buildGenerateOptions— camelize answers, nest db fields, merge with full configThe core flow in each CLI becomes:
packages/cli/src/commands/codegen.tswent from 160 → 71 lines.graphql/codegen/src/cli/index.tswent from 239 → 148 lines.Review & Testing Checklist for Human
graphql-codegen --config ./config.ts --output ./overrideand verify CLI flags override config values while config-only fields (tables, hooks, queryKeys) pass throughgraphql-codegenwith no config file and no CLI flags — verify prompts appear and work correctlyhyphenateKeysedge cases: Check thatschemaFile→schema-file,reactQuery→react-query,apiNames→api-namesall transform correctly (the regexkey.replace(/[A-Z]/g, m => '-' + m.toLowerCase())should handle these)graphql-codegen) still has multi-target loop logic — verify it works with a multi-target config fileNotes
packages/cli/__tests__/codegen.test.tsbypass the real transform logic — they mockseedArgvFromConfigas pass-through andbuildGenerateOptionswith simplified logic. Real integration testing is needed.--browser-compatiblewas a deprecated no-op; removing it is a breaking change for anyone passing the flag (they'll get an unknown flag warning from minimist)feat/graphql-codegen-orm-core— the cumulative diff to main is large because it includes the ORM-as-core refactor. The CLI cleanup is the final commit (7720cc4cd).Link to Devin run: https://app.devin.ai/sessions/a93d427c49214dce877d1fedee950c04
Requested by: @pyramation