Skip to content

fix(drizzle): generate per-enum filter input types for pg enum columns#380

Merged
xcfox merged 2 commits into
mainfrom
cursor/fix-enum-column-filters-21f4
Jul 6, 2026
Merged

fix(drizzle): generate per-enum filter input types for pg enum columns#380
xcfox merged 2 commits into
mainfrom
cursor/fix-enum-column-filters-21f4

Conversation

@xcfox

@xcfox xcfox commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #378.

When using drizzleResolverFactory, all PostgreSQL enum columns incorrectly shared a single PgEnumColumnFilters input type. The first enum column processed determined the eq/ne/inArray field types for every other enum column on the same table.

This PR changes enum column filter caching to use the GraphQL enum name (e.g. GenderFilters, EmployeeStatusFilters) instead of the Drizzle column type (PgEnumColumn).

Root cause

columnFilters() cached filter input types by column.columnType. All PostgreSQL enum columns share the same Drizzle column type (PgEnumColumn), so only the first enum column's GraphQL type was used for every subsequent enum filter.

Changes

  • Derive filter input names from the GraphQL enum type when the column resolves to a GraphQLEnumType
  • Keep existing behavior for non-enum columns (PgTextFilters, PgSerialFilters, etc.)
  • Add regression tests covering:
    • Multiple enum columns on one table
    • GraphQL validation against the correct enum in where filters
    • Shared enum reuse across tables/columns
  • Update example/documentation schema snapshots (PgEnumColumnFiltersRoleFilters)

Breaking change

PgEnumColumnFilters is replaced with per-enum filter types such as GenderFilters and EmployeeStatusFilters. This is the correct schema shape; clients that referenced PgEnumColumnFilters directly will need to update.

Test plan

  • pnpm exec vitest run test/enum-filters.spec.ts test/input-factory.spec.ts test/schema.spec.ts in packages/drizzle
  • pnpm run check:type in packages/drizzle
  • Verified employees(where: { status: { eq: ACTIVE } }) validates successfully and eq: MALE is rejected
Open in Web Open in Cursor 

PgEnumColumnFilters was cached by column.columnType, causing all enum
columns to share the first enum's filter type. Use the GraphQL enum name
as the cache key instead so each enum gets its own filter input.

Fixes #378
@xcfox
xcfox merged commit a5f878e into main Jul 6, 2026
4 checks passed
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.

使用drizzleResolverFactory时,生成的graphql类型存在问题

2 participants