fix(codegen): fix CLI codegen bugs - ORM signatures, String.call, type coercion, field filtering#733
Open
pyramation wants to merge 1 commit intomainfrom
Open
fix(codegen): fix CLI codegen bugs - ORM signatures, String.call, type coercion, field filtering#733pyramation wants to merge 1 commit intomainfrom
pyramation wants to merge 1 commit intomainfrom
Conversation
…e coercion, field filtering
- Fix String.call() -> String() in infra-generator.ts buildSetTokenHandler
(String.call() returns undefined, breaking token storage)
- Fix update/delete ORM signatures in table-command-generator.ts to use
{ where: { id } } instead of flat { id } (matching ORM API)
- Add type coercion for CLI string args -> proper GraphQL types
(Boolean, Int, Float, JSON, UUID, Enum) via generated fieldSchema
- Add field filtering to strip extra minimist fields (_, tty, etc.)
via stripUndefined() with schema-aware filtering
- Generate utils.ts with coerceAnswers(), stripUndefined(), parseMutationInput()
runtime helpers for all generated CLI commands
- Update test expectations and snapshots for new utils.ts file and
updated generated output (301/301 tests pass)
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.
fix(codegen): fix CLI codegen bugs — ORM signatures, String.call, type coercion, field filtering
Summary
Upstreams five bugs discovered during end-to-end CLI testing in constructive-db#509 into the codegen AST templates so future CLI generation produces correct code out of the box.
String.call(val)returnsundefined— tokens never storedinfra-generator.tsString.call(val)→String(val)update()/delete()called with{ id }instead of{ where: { id } }table-command-generator.tswhereobjecttable-command-generator.ts+ newutils-generator.tsfieldSchema, pipe throughcoerceAnswers()_,tty) leak into mutation datatable-command-generator.ts+ newutils-generator.tsstripUndefined()filters to schema-defined keys onlyanswersinstead of cleaned datatable-command-generator.tscleanedData(post-coercion, post-filtering) for data propsKey changes:
String.call()→String()inbuildSetTokenHandler(line 1648)buildFieldSchemaObject()to generate runtime type schemas from table fields{ where: { id } }ORM signaturerawAnswers→coerceAnswers()→answers→stripUndefined()→cleanedDatacoerceAnswers,stripUndefinedfrom../utilsor../../utils(target-aware)utils.tswithcoerceAnswers(),stripUndefined(),parseMutationInput()runtime helpersgenerateUtilsFile()into both single-target and multi-target CLI generationReview & Testing Checklist for Human
client.table.update({ where: { id }, data })andclient.table.delete({ where: { id } })match the actual ORM API. This was tested in constructive-db but worth double-checking the ORM source.parseMutationInputdead code: The generatedutils.tsincludesparseMutationInput()but it's never imported by generated table commands. It was used in hand-patched custom mutation commands in constructive-db. Should we wire it up for custom mutations in the codegen, or remove it?as stringtype assertion: Update/delete handlers castanswers.id as stringin the generated code. This assumesidis always a string after coercion (true for UUID type). Is this safe or should we use runtime validation?coerceAnswers()converts empty strings toundefinedfor ALL types including strings. This prevents sending""for optional fields, but means you can never intentionally set a string field to empty. Is this the desired behavior?Notes
utils-generator.tsuses string concatenation instead of Babel AST construction (different pattern from other generators, but simpler for this use case)Link to Devin run: https://app.devin.ai/sessions/d41228699b3a46de9e73cc13dda02882
Requested by: @pyramation