Repository navigation
fix(codegen): computed fields in CLI/ORM/docs, prune stale generated skills - #2012
Conversation
…skills - CLI: derive update fields from the patch type and create fields from the create input; never select or prompt for a field that takes arguments - ORM: fields returning an object type need a sub-selection and get a real interface + Select type instead of an unknown alias - docs: examples only select/set fields that exist and are selectable - skills: a generated skill directory holds exactly the files generated, and generated skills of dropped targets are removed
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
🧹 Nitpicks (3) — 🟢 3 low
The change tightens how the codegen classifies computed/argument-bearing fields and emits object-typed sub-selections, and introduces skill artifacts with pruning of stale generated skills.
Reviewed commit: 7fa99f1 |
There was a problem hiding this comment.
This PR refines graphql/codegen field classification (computed fields, writable fields per operation, registry-driven object sub-selections), adds array sub-selection support to the ORM Select template, and adds generated-skill writing plus stale-skill pruning — with two bugs worth fixing around a divergent InferSelectResult copy and unvalidated example fields.
Key findings
- 🟡 Array branch missing from ORM
InferSelectResultcopy — select-types.ts:181
| : NonNullable<TEntity[K]> extends readonly (infer Item)[] | ||
| ? | ||
| | InferSelectResult<NonNullable<Item>, NestedSelect>[] | ||
| | (null extends TEntity[K] ? null : never) |
There was a problem hiding this comment.
🟡 bug · medium
Array branch missing from ORM InferSelectResult copy
The PR added an array-element branch to InferSelectResult in templates/select-types.ts but not to the parallel copy in orm/select-types.ts (graphql/codegen/src/core/codegen/templates/select-types.ts:181-184). Generated ORM model code imports InferSelectResult from ../select-types — the stale copy — while generated client code uses the updated template copy, so for array object fields like avatarVersions: [FileVersion!] the two surfaces infer different result types: the model path recurses on the array itself instead of its items and yields a garbage or never-narrowed type. Users selecting the new object-array sub-selections through the model API get incorrect result types.
📋 Prompt for AI Agents
In graphql/codegen/src/core/codegen/orm/select-types.ts around lines 146-159, update both conditional arms of InferSelectResult to mirror graphql/codegen/src/core/codegen/templates/select-types.ts:179-187: after the ConnectionResult check, add a branch NonNullable<TEntity[K]> extends readonly (infer Item)[] ? InferSelectResult<NonNullable<Item>, NestedSelect>[] | (null extends TEntity[K] ? null : never) : ... before the plain-object recursion. This keeps the model-API copy in sync with the client-template copy, which this PR updated for array object fields.
Summary
Two generator defects block the schema regeneration in #2011 (and constructive-db#4389). Generator-only change: no generated output is committed here.
1. Computed fields (CLI does not compile)
Root cause:
getWritableFieldNames(core/codegen/utils.ts) only looked at the create input type.File/PlatformFilehave no create mutation, so it returnednull("no filter") and every entity field was treated as a column:buildSelectObjectemitteduploadUrl: truefor a field typed{ args, select }, andbuildMutationHandlerprompted for and sentdownloadUrl/uploadUrl/uploadVersionsin the patch.Everything is derived from the schema's input types and field args; there is no field-name list. Fields with arguments are left out of the default CLI select (they stay reachable through
--select).Same mistake elsewhere:
orm/input-types-generator.ts): a field returning an object type (uploadVersions: [FileVersion!]) was typeduploadVersions?: booleanwithtype FileVersion = unknown, souploadVersions: trueproduced an invalid query. It is now{ select: FileVersionSelect }(plusargswhen the field has any), with a realFileVersioninterface and Select type.InferSelectResulthandles list-valued nested selections.field: trueand listed computed fields in create/update examples. They now use the same schema-derived helpers.--select title,tsvRankwas hard-coded.tsvRankexists in no schema (the field is<col>TsvRank, e.g.searchTsvRank), andtitleonly on some tables. Examples now only reference fields the table has.Not changed:
Intervalis an object type in the schema but mapped tostringinSCALAR_TS_MAP, so it is still selected as a scalar. That predates this PR and needs its own decision.2. Stale generated skill files
Root cause: skills were written with
writeGeneratedFiles(..., { pruneStaleFiles: false })(core/generate.ts), and the writer's pruning only knows.tsfiles anyway, so a reference file that is no longer generated (references/request-upload-url.md) stayed forever. Separately,cleanStaleTargetsremoved the SDK directory of a dropped target but not its skills:{cli,hooks,orm}-publicare orphans, since there is nopublicschema any more.New
core/output/skills.ts:writeGeneratedSkills: after writing, each skill directory written in this run contains exactly the files generated for it.removeStaleGeneratedSkills(run bygenerateMultiwithcleanStaleTargets): removes a skill directory only if it is in a family this run generated (cli-/orm-/hooks-), itsSKILL.mdcarries the generator marker, and it is not a configured target. Hand-written skills are never touched; skills of a configured target that produced nothing (e.g.cluster, no tables) are kept.Verification
On #2011's content (
schema-update/post-file-urls-release), regenerated with this generator the way the hub workflow does (pnpm run generateinsdk/constructive-sdk,generate:migrate-client,sdk/constructive-cli,sdk/constructive-react):pnpm buildpasses insdk/constructive-cli,sdk/constructive-sdk,sdk/constructive-react,sdk/migrate-client(before: 14 errors instorage/cli/commands/{file,platform-file}.ts).git grep -il requestUploadUrl -- .agents/skillsreturns nothing;{cli,hooks,orm}-publicare gone, all hand-written skills remain.New tests fail without the fix:
computed-fields.test.ts,generated-skills.test.ts, and the "computed fields" block incli-generator.test.ts.After merge
schema-propagation.ymlso chore: update schemas from constructive-db (post-file-urls-release) #2011 is regenerated with this generator (nothing was pushed to that branch).@constructive-io/graphql-codegen(^5.25.31), so that package must be published before db#4389 is regenerated.sdk/before overlaying generated artifacts but not.agents/skills, so stale skills in constructive-db are only removed by the generator run itself, which this PR now does.Link to Devin session: https://app.devin.ai/sessions/b2b39b1bf543491ebf20fe7c5eee1710
Open in Devin Desktop: https://app.devin.ai/desktop/session/b2b39b1bf543491ebf20fe7c5eee1710?variant=devin
Requested by: @pyramation
🟢 Devin Review found nothing to fix · View findings · Follow Devin's work