Skip to content

fix(codegen): handle array types, computed fields, and orderBy enums in input-types-generator#833

Merged
pyramation merged 2 commits intomainfrom
devin/1773710295-fix-codegen-input-types-main
Mar 17, 2026
Merged

fix(codegen): handle array types, computed fields, and orderBy enums in input-types-generator#833
pyramation merged 2 commits intomainfrom
devin/1773710295-fix-codegen-input-types-main

Conversation

@pyramation
Copy link
Contributor

@pyramation pyramation commented Mar 17, 2026

Summary

Fixes several bugs in input-types-generator.ts where generated TypeScript types diverged from the GraphQL schema. The root cause for most issues is that field.type.isArray existed on CleanFieldType but was never checked anywhere in the input-types generator.

Array field types (e.g. deps: [String]): buildEntityProperties, buildPatchProperties, buildTableFilterProperties, and buildCreateDataFieldsFromTable now check isArray and generate string[] / StringListFilter instead of string / StringFilter.

Patch computed fields: buildPatchProperties now reads from the schema's Patch input type via typeRegistry when available (mirroring how Create inputs already work via buildCreateDataFieldsFromSchema), which correctly excludes plugin-injected computed fields like trgm similarity scores and searchScore.

OrderBy enum values: buildOrderByValues now uses the schema's enum as the source of truth when available, instead of generating FIELD_ASC/DESC for every table column (which produced values the server would reject).

Updates since last revision

Ran pnpm generate on the constructive-sdk schemas 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):

  • Array fields now correctly typed as string[]: tags, fieldIds, refFieldIds, kids, ktree, modules, parentIds, deps, requires, grantRoles, policyPrivileges, weights, langs, opClasses, includeFieldIds, path, etc.
  • OrderBy enums trimmed to match schema exactly (net ~1700 lines removed from generated output)
  • Patch types exclude computed trgm/searchScore fields and now use schema-accurate types (e.g. IntervalInput instead of string, File for upload fields)

Review & Testing Checklist for Human

  • Breaking type changes in Patch types: The schema-based Patch path introduces type changes beyond just removing computed fields. For example, SessionsModulePatch.sessionsDefaultExpiration changed from string | null to IntervalInput | null, and UserPatch/AppLevelPatch gained new *Upload?: File | null fields. Verify downstream consumers of the SDK handle these correctly.
  • OrderBy behavioral change: The old logic generated orderBy values for all fields then merged schema extras. The new logic uses the schema enum exclusively when typeRegistry is 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.
  • Patch schema-based path unit test gap: The new buildPatchProperties schema path (lines 1438–1463) uses typeRefToTs() 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.
  • Run codegen end-to-end against migrate-client schema: The constructive-sdk schemas were regenerated and included in this PR. If the migrate-client schema is available, also run cnc codegen on it and diff to confirm deps: string[], StringListFilter, and trimmed orderBy enums match exactly.

Notes

  • buildCreateDataFieldsFromSchema() (the primary Create input path) already handled arrays correctly via typeRefToTs(). Only the fallback buildCreateDataFieldsFromTable had the isArray bug, also fixed here.
  • scalarToFilterType() already accepted an isArray parameter — it just was never called with true.
  • 3 test suites fail pre-existingly due to missing workspace deps (@pgpmjs/core, pgsql-client, pgsql-seed) — unrelated to these changes.
  • The regenerated SDK files show a net reduction of ~1700 lines, almost entirely from removing invalid orderBy values and computed fields from Patch types.

Link to Devin session: https://app.devin.ai/sessions/772428a7ed2d4463b22ab00caa63663a
Requested by: @pyramation

…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.
@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

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
@pyramation pyramation merged commit f521f8e into main Mar 17, 2026
44 checks passed
@pyramation pyramation deleted the devin/1773710295-fix-codegen-input-types-main branch March 17, 2026 01:49
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