Skip to content

fix(codegen): computed fields in CLI/ORM/docs, prune stale generated skills - #2012

Merged
devin-ai-integration[bot] merged 3 commits into
mainfrom
feat/codegen-computed-fields-skill-prune
Nov 17, 2026
Merged

devin-ai-integration[bot] merged 3 commits into
mainfrom
feat/codegen-computed-fields-skill-prune

Conversation

@pyramation

@pyramation pyramation commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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 / PlatformFile have no create mutation, so it returned null ("no filter") and every entity field was treated as a column: buildSelectObject emitted uploadUrl: true for a field typed { args, select }, and buildMutationHandler prompted for and sent downloadUrl / uploadUrl / uploadVersions in the patch.

getWritableFieldNames(table, registry, 'create') -> fields of the create input
getWritableFieldNames(table, registry, 'update') -> fields of <Type>Patch
getSelectableScalarFields                        -> writable (create ∪ patch) AND isPlainSelectableField
isPlainSelectableField                           -> no args, not an OBJECT type

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 (orm/input-types-generator.ts): a field returning an object type (uploadVersions: [FileVersion!]) was typed uploadVersions?: boolean with type FileVersion = unknown, so uploadVersions: true produced an invalid query. It is now { select: FileVersionSelect } (plus args when the field has any), with a real FileVersion interface and Select type. InferSelectResult handles list-valued nested selections.
  • Hooks / ORM / CLI docs: examples selected every scalar field as field: true and listed computed fields in create/update examples. They now use the same schema-derived helpers.
  • Docs search examples: --select title,tsvRank was hard-coded. tsvRank exists in no schema (the field is <col>TsvRank, e.g. searchTsvRank), and title only on some tables. Examples now only reference fields the table has.

Not changed: Interval is an object type in the schema but mapped to string in SCALAR_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 .ts files anyway, so a reference file that is no longer generated (references/request-upload-url.md) stayed forever. Separately, cleanStaleTargets removed the SDK directory of a dropped target but not its skills: {cli,hooks,orm}-public are orphans, since there is no public schema 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 by generateMulti with cleanStaleTargets): removes a skill directory only if it is in a family this run generated (cli-/orm-/hooks-), its SKILL.md carries 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 generate in sdk/constructive-sdk, generate:migrate-client, sdk/constructive-cli, sdk/constructive-react):

  • pnpm build passes in sdk/constructive-cli, sdk/constructive-sdk, sdk/constructive-react, sdk/migrate-client (before: 14 errors in storage/cli/commands/{file,platform-file}.ts).
  • git grep -il requestUploadUrl -- .agents/skills returns nothing; {cli,hooks,orm}-public are 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 in cli-generator.test.ts.

After merge

  • Rerun constructive-hub's schema-propagation.yml so chore: update schemas from constructive-db (post-file-urls-release) #2011 is regenerated with this generator (nothing was pushed to that branch).
  • constructive-db uses the published @constructive-io/graphql-codegen (^5.25.31), so that package must be published before db#4389 is regenerated.
  • The hub workflow wipes 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

Devin Review

…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
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@luxor-code-review

luxor-code-review Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

🧹 Nitpicks (3) — 🟢 3 low
  • 🟢 Fallback id field not validated against real table fields (docs-utils.ts:341) — The new field-validation guard filters extra select fields against allFieldNames, but the display-field fallback can resolve to the literal id without validating it (graphql/codegen/src/core/codegen/docs-utils.ts:341), and the pagination example prepends id unconditionally (graphql/codegen/src/core/codegen/docs-utils.ts:441-443).
  • 🟢 Unified CLI skills write result ignored (generate.ts:832) — At graphql/codegen/src/core/generate.ts:832-833 the WriteSkillsResult from writeGeneratedSkills for unified-CLI skills is never checked for success, unlike the per-target call at generate.ts:411-419 which returns on failure.
  • 🟢 Entity-typed computed fields still emitted as field: true (input-types-generator.ts:885) — The new object-type sub-selection logic bails out when the field's gqlType matches a table name (tableByName.has(...) at graphql/codegen/src/core/codegen/orm/input-types-generator.ts:885-889), so a non-relation computed field that returns another entity's OBJECT type still falls into the boolean branch and generates field: true in the XSelect type.

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.

Files Change
graphql/codegen/src/core/codegen/utils.ts, docs-utils.ts Registry-aware classification: getWritableFieldNames becomes operation-specific, isPlainSelectableField excludes OBJECT types, and search examples filter select fields against real table fields.
graphql/codegen/src/core/codegen/orm/input-types-generator.ts, templates/select-types.ts Computed fields returning entity OBJECT types now emit ${Type}Select sub-selection types and an array-element branch in InferSelectResult.
graphql/codegen/src/core/codegen/cli/table-command-generator.ts, cli/docs-generator.ts, orm/docs-generator.ts, hooks-docs-generator.ts Generated command/doc examples receive table context and operation-specific writable fields; delete no longer gets writable fields.
graphql/codegen/src/core/output/skills.ts, core/generate.ts, core/output/index.ts New skill-writing plumbing with family-based stale-skill pruning in generateMulti, plus tests and snapshot updates across the codegen suite.

Reviewed commit: 7fa99f1

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +181 to +184
: NonNullable<TEntity[K]> extends readonly (infer Item)[]
?
| InferSelectResult<NonNullable<Item>, NestedSelect>[]
| (null extends TEntity[K] ? null : never)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@devin-ai-integration
devin-ai-integration Bot merged commit 0326ce9 into main Nov 17, 2026
21 checks passed
@devin-ai-integration
devin-ai-integration Bot deleted the feat/codegen-computed-fields-skill-prune branch November 17, 2026 05:10
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.

1 participant