Skip to content

feat: add dedicated test suite for graphile-connection-filter#806

Open
pyramation wants to merge 23 commits intomainfrom
devin/1773370456-connection-filter-tests
Open

feat: add dedicated test suite for graphile-connection-filter#806
pyramation wants to merge 23 commits intomainfrom
devin/1773370456-connection-filter-tests

Conversation

@pyramation
Copy link
Contributor

feat: add dedicated test suite for graphile-connection-filter

Summary

Adds a comprehensive test suite for the v5-native graphile-connection-filter plugin using the existing graphile-test infrastructure. Previously, the connection filter plugin was only tested indirectly through satellite plugin tests (search, pgvector). This PR adds 51 direct tests across 6 test suites:

  • Scalar operators (17 tests): equalTo, notEqualTo, distinctFrom, isNull, in/notIn, comparison operators, pattern matching (like, includes, startsWith, endsWith + insensitive variants), boolean filters, implicit AND
  • Logical operators (5 tests): and, or, not, nested combinations
  • Relation filters (9 tests): forward (child→parent), backward one-to-one, backward one-to-many (some/every/none), exists fields, combined local + relation filters
  • Computed column filters (2 tests): schema introspection + functional filtering
  • Schema introspection (7 tests): filter types per table, operator fields per scalar type, logical operator fields, relation filter fields, computed column fields
  • Options/toggles (5 tests): connectionFilterRelations, connectionFilterComputedColumns, connectionFilterLogicalOperators, connectionFilterAllowedOperators, connectionFilterOperatorNames

Also adds graphile/graphile-connection-filter to the CI test matrix (41 jobs total).

Review & Testing Checklist for Human

  • Verify all 51 tests pass in CI. These tests could NOT be run locally (no PostgreSQL on the dev machine). Every assertion is based on mental analysis of the seed data and assumed PostGraphile inflection behavior — none have been validated against a real database. This is the primary risk.
  • Check relation filter field name assumptions. Tests assume inflected names like categoryByCategoryId, reviewsByProductIdExist, productDetailByProductId, productsByCategoryId. If PostGraphile's inflection produces different names (e.g., reviewsByProductIdExists vs reviewsByProductIdExist), those tests will silently fail or error.
  • Verify backward relation some/every/none syntax. The tests assume productsByCategoryId: { some: { isAvailable: { equalTo: true } } } structure. Confirm this matches the actual ConnectionFilterBackwardRelationsPlugin output.
  • Check computed column inflection. Tests assume fullLabel and displayName as the inflected names for items_full_label() and products_display_name() SQL functions. Confirm against actual schema.
  • Validate test data math. For example, the distinctFrom test expects 4 rows — verify this matches the actual seed data + SQL NULL semantics. The relation filter tests (e.g., "categories where ALL products are available → 2 results") rely on manual counts.

Test Plan

  1. Wait for CI to run the new graphile/graphile-connection-filter test job
  2. If tests fail, examine the error messages for inflection mismatches or incorrect expected counts
  3. Optionally: manually inspect the generated GraphQL schema (e.g., via introspection query) to verify filter type structure matches test assumptions

Notes

Implements a from-scratch PostGraphile v5 native connection filter plugin,
replacing the upstream postgraphile-plugin-connection-filter dependency.

New package: graphile/graphile-connection-filter/

Plugin architecture (7 plugins):
- ConnectionFilterInflectionPlugin: filter type naming conventions
- ConnectionFilterTypesPlugin: registers per-table and per-scalar filter types
- ConnectionFilterArgPlugin: injects filter arg on connections via applyPlan
- ConnectionFilterAttributesPlugin: adds per-column filter fields
- ConnectionFilterOperatorsPlugin: standard/sort/pattern/jsonb/inet/array/range operators
- ConnectionFilterCustomOperatorsPlugin: addConnectionFilterOperator API for satellite plugins
- ConnectionFilterLogicalOperatorsPlugin: and/or/not logical composition

Key features:
- Full v5 native: uses Grafast planning, PgCondition, codec system, behavior registry
- EXPORTABLE pattern for schema caching
- Preserves addConnectionFilterOperator API for PostGIS, search, pgvector, textsearch plugins
- No relation filter plugins (simplifies configuration vs upstream)
- Preset factory: ConnectionFilterPreset(options)

Also updates graphile-settings to use the new workspace package.
…Operator

filterType is for table-level filter types (UserFilter), while filterFieldType
is for scalar operator types (StringFilter). Satellite plugins pass scalar type
names, so the lookup must use filterFieldType to match the registration in
ConnectionFilterTypesPlugin. Previously worked by coincidence since both
inflections produce the same output, but would silently fail if a consumer
overrode one inflection but not the other.
Adds computed column filter support — allows filtering on PostgreSQL functions
that take a table row as their first argument and return a scalar.

Controlled by connectionFilterComputedColumns schema option. The preset factory
includes the plugin only when the option is truthy (default in preset: true,
but constructive-preset sets it to false).
- Remove phantom postgraphile-plugin-connection-filter dep from graphile-pgvector-plugin (never used)
- Remove phantom postgraphile-plugin-connection-filter dep from graphile-pg-textsearch-plugin (never used)
- Update graphile-plugin-connection-filter-postgis to use graphile-connection-filter workspace dep with typed imports
- Update graphile-search-plugin to use graphile-connection-filter workspace dep with typed imports
- Replace (build as any).addConnectionFilterOperator casts with properly typed build.addConnectionFilterOperator
…on-filter

- Update search plugin, pgvector, and postgis test files to import from
  graphile-connection-filter instead of postgraphile-plugin-connection-filter
- Use ConnectionFilterPreset() factory instead of PostGraphileConnectionFilterPreset
- Import ConnectionFilterOperatorSpec type from graphile-connection-filter
- Fix smart quote characters in filter descriptions to match existing snapshots
…ion filter tests

- Add graphile-connection-filter as devDependency in graphile-pgvector-plugin
  (test file imports ConnectionFilterPreset but package had no dependency)
- Skip connectionFilterRelations tests in search plugin (relation filters
  are intentionally not included in the v5-native plugin; they were disabled
  in production via disablePlugins with the old plugin)
…toggle

- ConnectionFilterForwardRelationsPlugin: filter by FK parent relations
- ConnectionFilterBackwardRelationsPlugin: filter by backward relations (one-to-one + one-to-many with some/every/none)
- connectionFilterRelations toggle in preset (default: false)
- Un-skip relation filter tests in search plugin
- Updated augmentations, types, and exports
… at runtime

The preset factory now always includes relation plugins in the plugin list.
Each plugin checks build.options.connectionFilterRelations at runtime and
early-returns if disabled. This allows the toggle to be set by any preset
in the chain, not just the ConnectionFilterPreset() call.
Enables relation filter fields in the production schema:
- Forward: filter by FK parent (e.g. clientByClientId on OrderFilter)
- Backward: filter by children with some/every/none
- Codegen will pick up the new filter fields automatically
- Search plugin: isPgCondition → isPgConnectionFilter scope
- BM25 plugin: isPgCondition → isPgConnectionFilter scope
- Disable PgConditionArgumentPlugin and PgConditionCustomFieldsPlugin in preset
- Update all tests from condition: {...} to filter: {...}
- Add graphile-connection-filter devDependency to BM25 plugin
- Update search plugin graceful degradation tests to use filter

BREAKING CHANGE: The condition argument has been removed entirely.
All filtering now uses the filter argument exclusively.
- Search plugin plugin.test.ts: condition → filter syntax, add ConnectionFilterPreset
- Server-test: condition → filter in query with equalTo operator
- Clear stale snapshots (schema-snapshot, introspection) for regeneration
- Search plugin: update snapshot keys to match renamed filter-based tests
- Schema snapshot: remove all condition arguments and XxxCondition input types
- Introspection snapshot: remove condition arg and UserCondition type
- Kept conditionType in _meta schema (unrelated to deprecated condition arg)
… behavior for pgCodecRelation, update schema snapshot with relation filter types
…y filter at applyPlan level

Top-level empty filter {} is now treated as 'no filter' (skipped) instead of
throwing an error. Nested empty objects in and/or/not and relation filters are
still rejected. This removes the need for the connectionFilterAllowEmptyObjectInput
workaround in pgvector tests.
- Extract shared getQueryBuilder utility into graphile-connection-filter/src/utils.ts
- Remove duplicate getQueryBuilder from search, BM25, and pgvector plugins
- Replace (build as any).dataplanPg with build.dataplanPg (already typed on Build)
- Replace (build as any).behavior with build.behavior (already typed on Build)
- Replace (build as any).input.pgRegistry with build.input.pgRegistry (already typed)
- Remove scope destructuring as any casts (pgCodec already typed on ScopeInputObject)
- Add pgCodec comment to augmentations.ts noting it's already declared by graphile-build-pg
- Export getQueryBuilder from graphile-connection-filter for satellite plugin use
Adds index safety check for relation filter fields. When enabled (default: true),
relation filter fields are only created for FKs with supporting indexes.
This prevents generating EXISTS subqueries that would cause sequential scans
on large tables.

Uses PgIndexBehaviorsPlugin's existing relation.extensions.isIndexed metadata
which is set at gather time. The check runs at schema build time with zero
runtime cost.

Applied to both forward and backward relation filter plugins.
Comprehensive test coverage using graphile-test infrastructure:
- Scalar operators: equalTo, notEqualTo, distinctFrom, isNull, in/notIn,
  lessThan, greaterThan, like, iLike, includes, startsWith, endsWith
- Logical operators: and, or, not, nested combinations
- Relation filters: forward (child->parent), backward one-to-one,
  backward one-to-many (some/every/none), exists fields
- Computed column filters
- Schema introspection: filter types, operator fields, relation fields
- Options toggles: connectionFilterRelations, connectionFilterComputedColumns,
  connectionFilterLogicalOperators, connectionFilterAllowedOperators,
  connectionFilterOperatorNames

Also adds graphile/graphile-connection-filter to CI matrix (41 jobs).
@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