Skip to content

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

Open
pyramation wants to merge 8 commits intomainfrom
feat/cli-cleanup
Open

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

Conversation

@pyramation
Copy link
Contributor

refactor(cli): simplify arg parsing, remove --browser-compatible

Builds on PR #691 (devin/1770496336-fix-ast-regression). The CLI cleanup is the final commit (13c06dfc8); the rest of the diff is from the parent branch's ORM-as-core refactor + AST regression fix.

Summary

Replaces the manual field-by-field CLI argument parsing with a generic transform pipeline, and removes the deprecated --browser-compatible flag entirely.

Before: Both CLI entry points had ~3 redundant layers duplicated across each file:

  1. Manual cliOverrides object built with per-field if-statements checking both argv['kebab-case'] and argv.camelCase
  2. A hasNonInteractiveArgs guard re-listing every flag a third time
  3. Post-prompt field-by-field mapping into generate() options

After: Generic utilities in shared.ts:

  • hyphenateKeys / camelizeArgv — bidirectional key transforms
  • 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

Core flow 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: 160 → 71 lines
graphql/codegen/src/cli/index.ts: 239 → 148 lines

Review & Testing Checklist for Human

  • Test config + CLI override flow: Run graphql-codegen --config ./config.ts --output ./override — verify CLI flags override config values while config-only fields (tables, hooks, queryKeys) pass through unchanged
  • Verify key round-trip: Check that schemaFileschema-fileschemaFile works correctly through the transform chain. Edge cases: apiNames, reactQuery, dryRun
  • Test interactive prompting: Run graphql-codegen with no config and no CLI flags — verify prompts appear and work
  • Test multi-target config: The standalone CLI still has multi-target loop logic — verify it works with a multi-target config file
  • Breaking change: --browser-compatible is removed. Anyone passing this flag will get no error but the flag is silently ignored

Notes

  • The test mocks in packages/cli/__tests__/codegen.test.ts bypass the real transform logic — they mock seedArgvFromConfig as pass-through. Real integration testing is needed.
  • This PR is branched from devin/1770496336-fix-ast-regression (PR fix(codegen): convert string concatenation to Babel AST and template-copy patterns #691). The cumulative diff to main is large because it includes the ORM-as-core refactor. The CLI cleanup is the final commit.

Link to Devin run: https://app.devin.ai/sessions/a93d427c49214dce877d1fedee950c04
Requested by: @pyramation

yyyyaaa and others added 8 commits February 6, 2026 01:59
…copy patterns

- Convert queries.ts, mutations.ts, custom-queries.ts, custom-mutations.ts from lines.push() string concatenation to Babel AST generation
- Convert client.ts and selection.ts from string template literals to template-copy pattern
- Add hooks-ast.ts shared helper library for Babel AST node construction
- Add template files: hooks-client.ts, hooks-selection.ts
- Add AGENTS.md with codegen rules (AST-only, no string concat, templates as files)
- Update test snapshots for Babel formatting changes (whitespace/formatting only)
…-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