Skip to content

fix(codegen): exclude computed fields from default CLI select objects#815

Merged
pyramation merged 2 commits intomainfrom
devin/1773529303-codegen-exclude-computed-fields
Mar 14, 2026
Merged

fix(codegen): exclude computed fields from default CLI select objects#815
pyramation merged 2 commits intomainfrom
devin/1773529303-codegen-exclude-computed-fields

Conversation

@pyramation
Copy link
Contributor

@pyramation pyramation commented Mar 14, 2026

fix(codegen): exclude computed fields from default CLI select objects

Summary

Generated CLI handlers (handleList, handleGet, and mutation response selects) were including computed fields like descriptionTrgmSimilarity, prefixTrgmSimilarity, and searchScore in their default select objects. These fields are added by the unified search plugin and return null unless a search filter is active — they're noise in default CLI output.

The fix uses the typeRegistry (already available in generateTableCommand) to determine which fields exist in the create input type. Fields not present in the create input are considered computed/plugin-added and are excluded from default selections. When typeRegistry is not provided, the behavior is unchanged (all scalar fields selected).

New shared helpers in utils.ts:

  • resolveInnerInputType(inputTypeName, typeRegistry) — resolves PostGraphile's CreateXInput → { x: XInput } wrapper to get the actual field set
  • getWritableFieldNames(table, typeRegistry?) — returns the set of field names present in the create input type, or null if no registry
  • getSelectableScalarFields(table, typeRegistry?) — composes getScalarFields + getWritableFieldNames into a single reusable call

These were previously private/duplicated inside table-command-generator.ts. Now any generator (CLI, docs, hooks, ORM) can reuse them.

Changed functions in table-command-generator.ts:

  • buildSelectObject(table)buildSelectObject(table, typeRegistry?) — now calls getSelectableScalarFields
  • buildListHandler / buildGetHandler — accept and forward typeRegistry
  • buildMutationHandler — its buildSelectObject(table) call now also passes typeRegistry
  • Removed local resolveInnerInputType and getWritableFieldNames (now imported from utils.ts)

Review & Testing Checklist for Human

  • Verify createdAt/updatedAt are not over-excluded: The filter uses "fields present in the create input type" as the inclusion set. If createdAt/updatedAt are excluded from create inputs (common for auto-managed timestamps), they will also disappear from the default select in list/get handlers. Run codegen against a real schema and inspect the generated handleList output to confirm important read-only fields are still present. This is the highest-risk item in this PR.
  • Confirm fallback behavior when typeRegistry is undefined: getWritableFieldNames returns null when no registry is provided, which makes the filter a no-op. Verify that codegen paths without a typeRegistry (e.g., tests using fixtures) still generate correct output.
  • Regenerate CLI commands against the dashboard/production schema to verify the actual generated output looks correct — search score fields are gone, but all expected columns remain.

Notes

  • The existing 315 codegen tests all pass, but they likely exercise the typeRegistry = undefined fallback path (no-op filter), so they do not validate the new filtering behavior against a real schema with computed fields.
  • The buildMutationHandler previously had access to typeRegistry for filtering editableFields (what goes in the data object), but its select object wasn't filtered. Now the mutation response select is also filtered, which is consistent.
  • getFieldsWithDefaults remains in table-command-generator.ts but now imports resolveInnerInputType from utils.ts instead of using a local copy.

Devin Session: https://app.devin.ai/sessions/cf88f3fd383b4421a5169ed01612899d
Requested by: @pyramation

Uses getWritableFieldNames (which checks the create input type) to filter
out computed fields like search scores (descriptionTrgmSimilarity,
searchScore, etc.) and other plugin-added fields (hashUuid) from the
default select in handleList, handleGet, and mutation response handlers.

Fields not present in the create input type are considered computed and
are excluded from default selection. They can still be explicitly
requested in custom queries.
@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

Move resolveInnerInputType, getWritableFieldNames, and new
getSelectableScalarFields helper into utils.ts as shared abstractions.

These helpers centralize the concept of 'real database columns vs
computed plugin fields' so any generator (CLI, docs, hooks, ORM) can
reuse them. getSelectableScalarFields composes getScalarFields +
getWritableFieldNames into a single call.

Remove duplicated resolveInnerInputType and getWritableFieldNames from
table-command-generator.ts — it now imports them from utils.
@pyramation pyramation merged commit d18f708 into main Mar 14, 2026
44 checks passed
@pyramation pyramation deleted the devin/1773529303-codegen-exclude-computed-fields branch March 14, 2026 23:20
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