Skip to content

refactor(cli): simplify arg parsing with generic transforms, remove --browser-compatible#692

Open
pyramation wants to merge 7 commits intomainfrom
fix/cli-cleanup
Open

refactor(cli): simplify arg parsing with generic transforms, remove --browser-compatible#692
pyramation wants to merge 7 commits intomainfrom
fix/cli-cleanup

Conversation

@pyramation
Copy link
Contributor

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-compatible flag entirely.

Before: Each CLI file had ~3 redundant layers — manual cliOverrides built field-by-field with if-statements, a hasNonInteractiveArgs guard duplicating the same flag list, and a post-prompt field-by-field mapping into generate() 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 the db.schemas/db.apiNames structure
  • seedArgvFromConfig — merge config file values into argv (config as defaults, CLI flags override)
  • buildGenerateOptions — camelize answers, nest db fields, merge with full config

The core flow in each CLI becomes:

const seeded = seedArgvFromConfig(argv, fileConfig);
const answers = await prompter.prompt(seeded, codegenQuestions);
const options = buildGenerateOptions(answers, fileConfig);
const result = await generate(options);

packages/cli/src/commands/codegen.ts went from 160 → 71 lines. graphql/codegen/src/cli/index.ts went from 239 → 148 lines.

Review & Testing Checklist for Human

  • Test config file + CLI override flow: Run graphql-codegen --config ./config.ts --output ./override and verify CLI flags override config values while config-only fields (tables, hooks, queryKeys) pass through
  • Test interactive prompting: Run graphql-codegen with no config file and no CLI flags — verify prompts appear and work correctly
  • Verify hyphenateKeys edge cases: Check that schemaFileschema-file, reactQueryreact-query, apiNamesapi-names all transform correctly (the regex key.replace(/[A-Z]/g, m => '-' + m.toLowerCase()) should handle these)
  • Test multi-target config: The standalone CLI (graphql-codegen) still has multi-target loop logic — verify it works with a multi-target config file

Notes

  • The test mocks in packages/cli/__tests__/codegen.test.ts bypass the real transform logic — they mock seedArgvFromConfig as pass-through and buildGenerateOptions with simplified logic. Real integration testing is needed.
  • --browser-compatible was a deprecated no-op; removing it is a breaking change for anyone passing the flag (they'll get an unknown flag warning from minimist)
  • This PR is branched from 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

yyyyaaa and others added 7 commits February 6, 2026 01:59
…-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
@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.

2 participants