fix(drizzle): generate per-enum filter input types for pg enum columns#380
Merged
Conversation
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
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 #378.
When using
drizzleResolverFactory, all PostgreSQL enum columns incorrectly shared a singlePgEnumColumnFiltersinput type. The first enum column processed determined theeq/ne/inArrayfield 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 bycolumn.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
GraphQLEnumTypePgTextFilters,PgSerialFilters, etc.)wherefiltersPgEnumColumnFilters→RoleFilters)Breaking change
PgEnumColumnFiltersis replaced with per-enum filter types such asGenderFiltersandEmployeeStatusFilters. This is the correct schema shape; clients that referencedPgEnumColumnFiltersdirectly will need to update.Test plan
pnpm exec vitest run test/enum-filters.spec.ts test/input-factory.spec.ts test/schema.spec.tsinpackages/drizzlepnpm run check:typeinpackages/drizzleemployees(where: { status: { eq: ACTIVE } })validates successfully andeq: MALEis rejected