fix(codegen): handle array types, computed fields, and orderBy enums in input-types-generator#833
Merged
pyramation merged 2 commits intomainfrom Mar 17, 2026
Conversation
…in input-types-generator
Fix 6 bugs in the ORM input-types code generator:
1. Entity types: array fields (e.g. deps: [String]) now correctly generate
string[] instead of string by checking field.type.isArray
2. Patch types: same isArray fix for patch input properties
3. Filter types: array fields now use StringListFilter instead of
StringFilter by passing isArray to scalarToFilterType()
4. Patch types: now reads from schema's Patch input type (via
typeRegistry) to exclude computed/virtual fields (e.g. trgm
similarity, searchScore) that the server would reject
5-6. OrderBy types: now uses the schema's enum as source of truth
instead of naively generating ASC/DESC for every table field,
which produced invalid values not supported by the server
Also fixes the same isArray bug in buildCreateDataFieldsFromTable()
fallback path for consistency.
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:
|
Re-ran codegen on constructive-sdk schemas to reflect: - Array fields now correctly typed as string[] instead of string - OrderBy enums now match schema (no extra field-derived values) - Patch types exclude computed fields when schema type is available
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.
Summary
Fixes several bugs in
input-types-generator.tswhere generated TypeScript types diverged from the GraphQL schema. The root cause for most issues is thatfield.type.isArrayexisted onCleanFieldTypebut was never checked anywhere in the input-types generator.Array field types (e.g.
deps: [String]):buildEntityProperties,buildPatchProperties,buildTableFilterProperties, andbuildCreateDataFieldsFromTablenow checkisArrayand generatestring[]/StringListFilterinstead ofstring/StringFilter.Patch computed fields:
buildPatchPropertiesnow reads from the schema's Patch input type viatypeRegistrywhen available (mirroring how Create inputs already work viabuildCreateDataFieldsFromSchema), which correctly excludes plugin-injected computed fields like trgm similarity scores and searchScore.OrderBy enum values:
buildOrderByValuesnow uses the schema's enum as the source of truth when available, instead of generatingFIELD_ASC/DESCfor every table column (which produced values the server would reject).Updates since last revision
Ran
pnpm generateon theconstructive-sdkschemas to regenerate the SDK input-types with the codegen fixes applied. The regenerated files confirm the fixes across all 4 schema targets (admin, auth, objects, public — 147 tables total):string[]:tags,fieldIds,refFieldIds,kids,ktree,modules,parentIds,deps,requires,grantRoles,policyPrivileges,weights,langs,opClasses,includeFieldIds,path, etc.IntervalInputinstead ofstring,Filefor upload fields)Review & Testing Checklist for Human
SessionsModulePatch.sessionsDefaultExpirationchanged fromstring | nulltoIntervalInput | null, andUserPatch/AppLevelPatchgained new*Upload?: File | nullfields. Verify downstream consumers of the SDK handle these correctly.typeRegistryis available — the field-derived values are only a fallback. Verify this doesn't drop valid orderBy values in edge cases where the schema enum might be stale or incomplete relative to table fields.buildPatchPropertiesschema path (lines 1438–1463) usestypeRefToTs()to read from the TypeRegistry's Patch input type, but the existing test fixtures don't include a Patch type in the TypeRegistry — only the table-field fallback is exercised by unit tests. Consider adding a test case with a Patch input in the registry to cover the primary path.cnc codegenon it and diff to confirmdeps: string[],StringListFilter, and trimmed orderBy enums match exactly.Notes
buildCreateDataFieldsFromSchema()(the primary Create input path) already handled arrays correctly viatypeRefToTs(). Only the fallbackbuildCreateDataFieldsFromTablehad the isArray bug, also fixed here.scalarToFilterType()already accepted anisArrayparameter — it just was never called withtrue.@pgpmjs/core,pgsql-client,pgsql-seed) — unrelated to these changes.Link to Devin session: https://app.devin.ai/sessions/772428a7ed2d4463b22ab00caa63663a
Requested by: @pyramation