Skip to content

fix(codegen): include plugin-injected fields in condition and orderBy types#789

Merged
pyramation merged 2 commits intomainfrom
devin/1773277094-fix-vector-codegen
Mar 12, 2026
Merged

fix(codegen): include plugin-injected fields in condition and orderBy types#789
pyramation merged 2 commits intomainfrom
devin/1773277094-fix-vector-codegen

Conversation

@pyramation
Copy link
Contributor

@pyramation pyramation commented Mar 12, 2026

fix(codegen): include plugin-injected fields in condition and orderBy types

Summary

The codegen's buildTableConditionProperties and buildOrderByValues only iterated over table.fields (database columns), so any fields injected by Graphile plugins (e.g., embeddingNearby from VectorSearchPlugin, or EMBEDDING_DISTANCE_ASC/DESC orderBy values) were silently dropped from generated TypeScript types.

This PR fixes three things:

  1. scalars.ts — Adds Vector: 'number[]' to SCALAR_TS_MAP so pgvector's Vector scalar resolves to a TypeScript type.
  2. input-types-generator.tsbuildTableConditionProperties and buildOrderByValues now accept an optional TypeRegistry and merge any extra fields/values present in the schema's condition/orderBy types that aren't derived from the table's own columns. A new helper collectConditionExtraInputTypes ensures referenced types (e.g., VectorNearbyInput) also get generated.
  3. Transitive type resolutiongenerateCustomInputTypes previously only followed nested types ending with "Input", so enum types like VectorMetric (referenced by VectorNearbyInput.metric) were silently dropped. Now follows all non-scalar types present in the typeRegistry.
  4. Tests — 6 new test cases covering plugin-injected condition fields, transitive enum resolution, field deduplication, plugin-injected orderBy values, and backwards compatibility when no TypeRegistry is provided.

All changes are backwards-compatible — the typeRegistry parameter is optional throughout.

Updates since last revision

  • Fixed transitive type resolution bug: generateCustomInputTypes (line ~1619) broadened from baseType.endsWith('Input') to !SCALAR_NAMES.has(baseType) && typeRegistry.has(baseType), so referenced enums and other non-scalar types are correctly followed and generated.
  • Added dedicated unit test for transitive enum resolution (VectorNearbyInputVectorMetric).
  • Extended existing test to also verify VectorMetric enum values (L2, INNER_PRODUCT, COSINE) appear in generated output.

Review & Testing Checklist for Human

  • Broadened transitive resolution safety: The change in generateCustomInputTypes now follows any non-scalar type that exists in the registry (not just *Input). The generatedTypes set prevents double-emission within this function, but types already emitted by earlier codegen stages (e.g., generateEnumTypes for table-column enums) could theoretically be duplicated in the output. Verify this doesn't cause issues with real schemas.
  • Type representation for plugin-injected condition fields: Plugin-injected fields use typeRefToTs(field.type) while table-derived fields use scalarToTsType(fieldType) + ' | null'. Verify the nullability semantics are correct for both paths (table fields always get | null, plugin fields get nullability from the TypeRef wrapper).
  • End-to-end validation: Run codegen against a real schema that uses graphile-pgvector-plugin and confirm the generated input-types.ts now includes embeddingNearby in condition types, VectorMetric enum, and distance-based orderBy values. The unit tests use mocked registries that may not perfectly match actual PostGraphile output.
  • Suggested test plan: Deploy a local PostGraphile instance with pgvector + VectorSearchPlugin, export the schema, run pnpm codegen against it, and inspect the generated input-types.ts for completeness. Alternatively, a follow-up PR (test(codegen): add vector schema integration test for plugin-injected fields #790) adds an integration test with a hand-crafted vector schema fixture.

Notes

… types

Previously, buildTableConditionProperties and buildOrderByValues only
iterated table.fields (database columns), missing any fields injected
by Graphile plugins (e.g., VectorSearchPlugin's embeddingNearby condition
field and EMBEDDING_DISTANCE_ASC/DESC orderBy values).

Changes:
- Add Vector scalar type mapping (number[]) to SCALAR_TS_MAP
- Modify buildTableConditionProperties to merge plugin-added fields
  from the TypeRegistry's condition type
- Modify buildOrderByValues to merge plugin-added enum values from
  the TypeRegistry's orderBy type
- Add collectConditionExtraInputTypes to discover and generate
  referenced input types (e.g., VectorNearbyInput, VectorMetric)
- Pass typeRegistry through to condition/orderBy generators
- Add comprehensive tests for plugin-injected condition and orderBy types

Fixes: constructive-io/constructive-planning#663
@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

Previously, generateCustomInputTypes only followed nested types whose
names ended with 'Input'. This meant enum types like VectorMetric
(referenced by VectorNearbyInput.metric) were silently dropped from
generated output, producing TypeScript with undefined type references.

Now follows all non-scalar types that exist in the typeRegistry,
including enums and other type kinds.

Added unit test verifying transitive enum resolution through
VectorNearbyInput → VectorMetric.
@pyramation pyramation force-pushed the devin/1773277094-fix-vector-codegen branch from b7db5e0 to 0ffda8e Compare March 12, 2026 02:14
@pyramation pyramation merged commit 0ffda8e into main Mar 12, 2026
86 checks passed
@pyramation pyramation deleted the devin/1773277094-fix-vector-codegen branch March 12, 2026 04:32
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