feat: add orm-test package — M:N + mega query integration tests against real PostgreSQL#869
Open
pyramation wants to merge 6 commits intomainfrom
Open
feat: add orm-test package — M:N + mega query integration tests against real PostgreSQL#869pyramation wants to merge 6 commits intomainfrom
pyramation wants to merge 6 commits intomainfrom
Conversation
…reSQL New graphql/orm-test package that exercises ORM M:N patterns against a live PostGraphile schema via graphile-test: - SQL fixtures: posts, tags, post_tags junction with @behavior +manyToMany - ManyToManyOptInPreset enabled for M:N connection fields - Tests: addTag (createPostTag), removeTag (deletePostTagByPostIdAndTagId, deletePostTagByRowId), CRUD, reverse M:N direction, unique constraint - 10/10 tests pass locally
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Exercises tsvector, BM25 (pg_textsearch), pg_trgm, pgvector, PostGIS, relation filters, scalar filters, and M:N junctions in one test suite. Crown jewel: a single GraphQL request combining all 7 plugin types with multi-signal ORDER BY (BM25 score + trgm similarity). 36 mega-query tests + 10 M:N tests = 46 total, all passing.
- Add codegen-helper.ts: orchestrates introspection → inferTables → generateOrm → compile → load at test runtime
- Add graphile-adapter.ts: wraps graphile-test query() as GraphQLAdapter for ORM client
- Rewrite orm-m2n.test.ts: uses generated ORM for findMany/create, raw GraphQL for delete (junction PK not inferred)
- Rewrite mega-query.test.ts: uses generated ORM for all 7 ConstructivePreset plugins
- Fix vectorEmbedding filter shape: VectorNearbyInput is flat {vector, distance}, not nested {nearby: {embedding}}
- Fix BM25 assertions: BM25 returns all rows with scores (0 for non-matches), doesn't filter
- Each test suite gets isolated __generated__/<name> directory to avoid parallel collisions
- Add @constructive-io/graphql-codegen dependency to orm-test package.json
- 48 tests pass (12 M:N + 36 mega query)
…er seed data
- Richer seed body texts for dramatic BM25 score separation
- Semantic vector embeddings clustered by category (restaurant/park/museum)
- Concrete assertions: BM25 ranking order, trgm similarity thresholds, tsvRank ranges
- Fix vectorEmbedding filter shape: use flat {vector, distance} (not nested nearby/embedding)
- 3 new pgvector cluster tests (restaurant, park, museum directions)
- searchScore composite signal test combining tsvector + BM25 + trgm
- 52 tests total, all passing
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
Adds a new
graphql/orm-testpackage that tests generated ORM models against a live PostgreSQL database viagraphile-test. Both test suites run the full codegen pipeline at test runtime (introspection →inferTablesFromIntrospection→generateOrm→ compile → dynamic import) and exercise the resulting ORM client.Codegen infrastructure (
__tests__/helpers/)codegen-helper.ts— orchestrates the full codegen pipeline against a live graphile-test schema: runs introspection, infers tables, generates ORM files, compiles TypeScript to JS, and returns thecreateClientfactory. Each test suite passes a uniquenameparameter to get its own__generated__/<name>/directory (avoids collisions when Jest runs suites in parallel).graphile-adapter.ts— implements theGraphQLAdapterinterface by wrapping graphile-test'squery()function, converting responses toQueryResult<T>discriminated unions for the ORM client.M:N integration tests (
orm-m2n.test.ts) — 12 testsposts,tags, and apost_tagsjunction table (with@behavior +manyToMany)ManyToManyOptInPresetto enable M:N connection fieldsfindManyandcreatemethods for queries and junction row creationinferTablesFromIntrospection)Mega query tests (
mega-query.test.ts) — 40 testsExercises all 7 ConstructivePreset plugins simultaneously via the ORM against a real Postgres DB seeded with NYC location data (
mega-seed.sql):tsvcolumn,tsvRankscore field with concrete range assertions (0.05–0.1)pg_textsearch) — relevance search onbodycolumn,bodyBm25Scorewith ranking-order assertions (Prospect Park > Central Park Cafe > Brooklyn Bridge Park > High Line for "park")name,nameTrgmSimilaritywith threshold assertions (Prospect Park > 0.35 for "park", Met Museum ≈ 0.7 for "museum"), typo handling ("Broklyn" → Brooklyn Bridge Park)embeddingcolumn (flatVectorNearbyInput:{vector, distance}), cluster tests for restaurant/park/museum directions,search_locations()functiongeomcolumn with GeoJSON bbox intersection filterisActive,rating), logical (and/or/not), relation (category,tags,tagsExist)location_amenitiesjunction table with add/remove via serial PKCrown jewel: a single ORM
findManycombining all 7 filter types with multi-signalorderBy: [BODY_BM25_SCORE_ASC, NAME_TRGM_SIMILARITY_DESC].52 total tests (12 M:N + 40 mega), all passing locally.
Updates since last revision
[1,0,0]finds restaurants,[0,1,0]finds parks,[0,0,1]finds museums using cosine distance threshold.searchScoreare populated and in expected ranges.vectorEmbeddingfilter shape —VectorNearbyInputis flat{vector: [1,0,0], distance: 0.5}, NOT nested{nearby: {embedding: [...]}}. The ORM mapswhere→ GraphQLwherearg (unified search plugin), which correctly applies distance filtering.query().inferTablesFromIntrospectionreportsprimaryKey: undefinedfor thepost_tagsjunction table, so the codegen skips delete method generation. Delete tests fall back to raw GraphQL mutations.Review & Testing Checklist for Human
< -0.5,< -2,< -3), trgm similarities (e.g.> 0.35,≈ 0.7), and tsvRank ranges (0.05–0.1) were calibrated againstpostgres-plus:18. Different Postgres versions, extension versions, or text configs could shift these values and cause test failures. Verify the thresholds have enough margin.tsvTsv,bm25Body,trgmName,vectorEmbedding,category,tags,tagsExist, andgeom.intersectsare added by Graphile plugins at runtime, not captured byinferTablesFromIntrospection. The ORM passes them through as untyped properties. Verify this is acceptable or whether the codegen should be enhanced to capture plugin filter fields.postgres-plus:18Docker image —mega-seed.sqlrequirespg_textsearch(BM25 index),postgis,vector, andpg_trgmextensions. If CI uses a different Postgres image, the mega query tests will fail atCREATE EXTENSION IF NOT EXISTS pg_textsearch.inferTablesFromIntrospectiondoesn't detect the composite PK onpost_tags, so the ORM skips generating delete methods. Verify whether this is a codegen gap to fix separately.Recommended test plan:
cd graphql/orm-test && pnpm test— all 52 tests should pass against a local Postgres runningpostgres-plus:18.Notes
orm-m2nuse fixed UUIDs (e.g.,11111111-...,aaaaaaaa-...) for deterministic assertions.anonymous/PUBLICrole gets full CRUD grants in both test schemas; appropriate for test isolation, not production.ivfflatindex useslists = 1which is only valid for the small (7-row) seed dataset.resolution:collapsed to single-line) from a pnpm version difference, plus minor version bumps (semver7.7.3→7.7.4,pg-protocol1.12.0→1.13.0).Link to Devin session: https://app.devin.ai/sessions/745d2d10b699452091e24131ba5edef2
Requested by: @pyramation