fix(codegen): convert string concatenation to Babel AST and template-copy patterns #691
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): 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) usedlines.push()string concatenation instead of proper Babel AST generation. This PR converts them back.Changes:
Converted 4 files from
lines.push()→ Babel AST (@babel/types+@babel/generator):queries.ts(239lines.pushcalls removed) — list + single query hooks, fetch, prefetchmutations.ts(157 calls) — create, update, delete mutation hookscustom-queries.ts(195 calls) — custom query hooks with variable handlingcustom-mutations.ts(47 calls) — custom mutation hooksConverted 2 files from string template literals → template-copy pattern:
client.ts→ reads from newtemplates/hooks-client.tsselection.ts→ reads from newtemplates/hooks-selection.tsNew shared helper library (
hooks-ast.ts, ~875 lines) — Reusable Babel AST node builders for imports, type references, function declarations, query/mutation patterns, etc.Added
AGENTS.mdingraphql/codegen/documenting three codegen rules: AST-only generation, no string concatenation, static templates as real files.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
buildFindManyCallExpr,returnUseQuery,buildMutationResultTypeproduce valid AST. Note: uses@ts-ignorefor Babel type parameter hacks.findTemplateFile()traverses up directories looking fortemplates/. Verify this works in production builds (dist/) not just source.lines.push()remains — Search the 4 converted files to ensure no string concatenation code generation remains.Recommended test plan:
pnpm buildingraphql/codegenpnpm testto verify all 204 tests passcnc codegen --react-query --endpoint <url> --output ./test-outputtsc --noEmitNotes
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