E2E validation that the generated ORM client (from @constructive-io/graphql-codegen)
works end-to-end with a real PostGraphile server, a real graphql-ws WebSocket
transport, and real PostgreSQL LISTEN/NOTIFY.
The test suite in __tests__/realtime-orm-client.integration.test.ts:
- Boots a real PostgreSQL test database via
pgsql-testand seeds it withsql/contact-seed.sql. - Builds a PostGraphile GraphQL schema with
RealtimeSubscriptionsPluginusinggraphile-realtime-test. - Starts a standalone
ws+graphql-wsWebSocket server on a random port. - Calls
generateOrm()to produce typed ORM client TypeScript source files for thecontacttable. - Compiles the generated files into a tmpdir with
tsc. - Creates a generated
OrmClientwired to the test WS server, callsclient.contact.subscribe(), firespg_notify()viactx.notifyChange(), and asserts that events arrive correctly.
| # | Name | What it proves |
|---|---|---|
| 1 | UPDATE event end-to-end | Generated subscribe() receives operation: 'UPDATE' when ctx.notifyChange() fires |
| 2 | INVALIDATE event (overflow) | notifyInvalidate() produces operation: 'INVALIDATE' with overflow: true |
| 3 | No events after unsubscribe | The returned Unsubscribe function truly cancels delivery |
You need a running PostgreSQL 17+ instance accessible on localhost:5432.
# Option A: use the pgpm Docker helper (recommended)
pgpm docker start --image pyramation/postgres:17 --recreate
eval "$(pgpm env)"
# Option B: set env vars directly
export PGHOST=localhost PGPORT=5432 PGUSER=postgres PGPASSWORD=password
# Run the tests
cd graphile/graphile-realtime-codegen-e2e
pnpm testThese tests are intentionally not run in CI — they require a live Docker PostgreSQL instance. Add a CI step only after wiring up the Docker service in the CI pipeline.
No emit_change trigger. The emit_change PL/pgSQL trigger that converts DML operations into pg_notify() calls lives in constructive-db, not in this monorepo. Events are simulated via ctx.notifyChange(), which fires pg_notify() directly on the root pg client (outside any transaction). A fully DB-trigger-driven test would require either checking out the constructive-db submodule or hand-writing the trigger SQL — out of scope for this minimal e2e harness.
Standalone WS server, not grafserv. The test WS server is created by graphile-realtime-test's getConnections(). It is a minimal ws + graphql-ws server. The production grafserv HTTP server does not accept WS upgrades in this branch without additional configuration.
pgpm workspaces is a SQL migration management tool (manages Sqitch-compatible PostgreSQL migrations). It is not the right abstraction for a runtime test harness — this package is a Jest test suite, not a SQL migration. pnpm workspaces (pnpm-workspace.yaml) is used instead (the standard mechanism for monorepo packages in this repo).
- Install the
emit_changetrigger SQL fromconstructive-dbso tests exercise the real DML trigger path. - Add filter args tests: watch a specific
idsset and assert that unwatched rows produceUNKNOWNevents (seerealtime-websocket.integration.test.tsfor the pattern). - Add a multi-subscriber concurrency test: two ORM clients subscribed simultaneously.
- Wire CI: add a
postgres:17Docker service to the GitHub Actions workflow and include this package in the test matrix.