Skip to content

fix(codegen): convert string concatenation to Babel AST and template-copy patterns#691

Open
pyramation wants to merge 7 commits intomainfrom
devin/1770496336-fix-ast-regression
Open

fix(codegen): convert string concatenation to Babel AST and template-copy patterns#691
pyramation wants to merge 7 commits intomainfrom
devin/1770496336-fix-ast-regression

Conversation

@pyramation
Copy link
Contributor

fix(codegen): convert string concatenation to Babel AST and template-copy patterns

Summary

This PR supersedes #689 and carries forward its ORM-as-core architecture while fixing an AST regression: 4 hook generator files (queries.ts, mutations.ts, custom-queries.ts, custom-mutations.ts) used lines.push() string concatenation instead of proper Babel AST generation. This PR converts them back.

Changes:

  1. Converted 4 files from lines.push() → Babel AST (@babel/types + @babel/generator):

    • queries.ts (239 lines.push calls removed) — list + single query hooks, fetch, prefetch
    • mutations.ts (157 calls) — create, update, delete mutation hooks
    • custom-queries.ts (195 calls) — custom query hooks with variable handling
    • custom-mutations.ts (47 calls) — custom mutation hooks
  2. Converted 2 files from string template literals → template-copy pattern:

    • client.ts → reads from new templates/hooks-client.ts
    • selection.ts → reads from new templates/hooks-selection.ts
  3. New shared helper library (hooks-ast.ts, ~875 lines) — Reusable Babel AST node builders for imports, type references, function declarations, query/mutation patterns, etc.

  4. Added AGENTS.md in graphql/codegen/ documenting three codegen rules: AST-only generation, no string concatenation, static templates as real files.

  5. 22 test snapshots updated — formatting-only changes (Babel's multi-line type literals, semicolons in type properties, double quotes). No logic changes.

Review & Testing Checklist for Human

  • Verify hooks-ast.ts correctness — This 875-line helper library is entirely new. Check that helper functions like buildFindManyCallExpr, returnUseQuery, buildMutationResultType produce valid AST. Note: uses @ts-ignore for Babel type parameter hacks.
  • Run codegen against a real schema — Unit tests only verify snapshots. Generate hooks against an actual GraphQL endpoint/schema to confirm output compiles and works at runtime.
  • Check template file resolutionfindTemplateFile() traverses up directories looking for templates/. Verify this works in production builds (dist/) not just source.
  • Confirm zero lines.push() remains — Search the 4 converted files to ensure no string concatenation code generation remains.
  • Review snapshot diffs — The 22 updated snapshots should only show whitespace/formatting changes, not logic changes.

Recommended test plan:

  1. Run pnpm build in graphql/codegen
  2. Run pnpm test to verify all 204 tests pass
  3. Generate hooks against a test schema: cnc codegen --react-query --endpoint <url> --output ./test-output
  4. Verify generated files compile with tsc --noEmit

Notes

This PR includes all changes from the base branch feat/graphql-codegen-orm-core (the ORM-as-core refactor from PR #689), plus the AST regression fixes. The workflow file changes and test-app additions are from that base branch.


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

yyyyaaa and others added 7 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)
@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