Skip to content

fix(codegen): include plugin-injected fields in condition/orderBy types + VectorFilter#791

Merged
pyramation merged 3 commits intomainfrom
devin/1773279354-fix-vector-codegen-v2
Mar 12, 2026
Merged

fix(codegen): include plugin-injected fields in condition/orderBy types + VectorFilter#791
pyramation merged 3 commits intomainfrom
devin/1773279354-fix-vector-codegen-v2

Conversation

@pyramation
Copy link
Contributor

fix(codegen): support pgvector types and plugin-injected condition/orderBy fields

Summary

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

This PR fixes four things:

  1. scalars.ts — Adds Vector: 'number[]' to SCALAR_TS_MAP and Vector: 'VectorFilter' to SCALAR_FILTER_MAP so pgvector's Vector scalar resolves correctly.
  2. Plugin-injected condition fieldsbuildTableConditionProperties now accepts an optional TypeRegistry and merges extra fields present in the schema's condition type that aren't derived from table columns. A new collectConditionExtraInputTypes helper ensures referenced types (e.g., VectorNearbyInput) get generated.
  3. Plugin-injected orderBy valuesbuildOrderByValues similarly merges extra enum values from the schema's orderBy type.
  4. 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.

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

Tests added: 7 new test cases covering VectorFilter generation, plugin-injected condition fields, transitive enum resolution, field deduplication, plugin-injected orderBy values, and backwards compatibility. 14 snapshots updated (mechanical — VectorFilter added to always-generated scalar filter types).

Review & Testing Checklist for Human

  • Broadened transitive resolution safety: The change in generateCustomInputTypes (line ~1619) 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.

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
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.
Adds Vector → VectorFilter mapping in SCALAR_FILTER_MAP and VectorFilter
config (equality + distinct operators) in SCALAR_FILTER_CONFIGS, so that
vector embedding fields in Filter types use VectorFilter instead of
falling back to StringFilter.

Includes unit test and updated snapshots.
@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

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