fix(codegen): exclude computed fields from default CLI select objects#815
Merged
pyramation merged 2 commits intomainfrom Mar 14, 2026
Merged
Conversation
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.
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:
|
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.
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): exclude computed fields from default CLI select objects
Summary
Generated CLI handlers (
handleList,handleGet, and mutation response selects) were including computed fields likedescriptionTrgmSimilarity,prefixTrgmSimilarity, andsearchScorein their defaultselectobjects. These fields are added by the unified search plugin and returnnullunless a search filter is active — they're noise in default CLI output.The fix uses the
typeRegistry(already available ingenerateTableCommand) 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. WhentypeRegistryis not provided, the behavior is unchanged (all scalar fields selected).New shared helpers in
utils.ts:resolveInnerInputType(inputTypeName, typeRegistry)— resolves PostGraphile'sCreateXInput → { x: XInput }wrapper to get the actual field setgetWritableFieldNames(table, typeRegistry?)— returns the set of field names present in the create input type, ornullif no registrygetSelectableScalarFields(table, typeRegistry?)— composesgetScalarFields+getWritableFieldNamesinto a single reusable callThese 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 callsgetSelectableScalarFieldsbuildListHandler/buildGetHandler— accept and forwardtypeRegistrybuildMutationHandler— itsbuildSelectObject(table)call now also passestypeRegistryresolveInnerInputTypeandgetWritableFieldNames(now imported fromutils.ts)Review & Testing Checklist for Human
createdAt/updatedAtare not over-excluded: The filter uses "fields present in the create input type" as the inclusion set. IfcreatedAt/updatedAtare excluded from create inputs (common for auto-managed timestamps), they will also disappear from the defaultselectin list/get handlers. Run codegen against a real schema and inspect the generatedhandleListoutput to confirm important read-only fields are still present. This is the highest-risk item in this PR.typeRegistryis undefined:getWritableFieldNamesreturnsnullwhen no registry is provided, which makes the filter a no-op. Verify that codegen paths without atypeRegistry(e.g., tests using fixtures) still generate correct output.Notes
typeRegistry = undefinedfallback path (no-op filter), so they do not validate the new filtering behavior against a real schema with computed fields.buildMutationHandlerpreviously had access totypeRegistryfor filteringeditableFields(what goes in thedataobject), but itsselectobject wasn't filtered. Now the mutation response select is also filtered, which is consistent.getFieldsWithDefaultsremains intable-command-generator.tsbut now importsresolveInnerInputTypefromutils.tsinstead of using a local copy.Devin Session: https://app.devin.ai/sessions/cf88f3fd383b4421a5169ed01612899d
Requested by: @pyramation