Skip to content

test(server-test): add CLI e2e tests against real PostgreSQL database#916

Open
pyramation wants to merge 1 commit intomainfrom
devin/1774614615-cli-e2e-tests
Open

test(server-test): add CLI e2e tests against real PostgreSQL database#916
pyramation wants to merge 1 commit intomainfrom
devin/1774614615-cli-e2e-tests

Conversation

@pyramation
Copy link
Copy Markdown
Contributor

Summary

Adds 5 end-to-end tests that exercise the full CLI pipeline: codegen → transpile → execute as child process against a running PostgreSQL database with a real GraphQL server.

Approach (Approach A):

  1. getConnections() spins up a real Postgres DB + GraphQL HTTP server
  2. generateCli() and generateOrm() produce TypeScript source files
  3. ts.transpileModule strips types without resolving imports (avoids needing all type packages in a temp dir)
  4. Appstash context is configured in a temp $HOME pointing at the test server endpoint
  5. A child process (spawn, not execFileSync) runs the compiled CLI against the live server
  6. stdout is parsed and assertions verify the results

Why spawn instead of execFileSync: The GraphQL server runs in the same Node.js process. Synchronous child execution blocks the event loop, preventing the server from responding — causing a deadlock/timeout.

5 focused corner-case tests:

  1. Paginated list with --where (dot-notation) + --fields projection
  2. Cursor-based forward pagination (--limit + --after)
  3. find-first with --where.name.equalTo
  4. Combined --where + --orderBy + --fields
  5. Empty result set handling

Package.json changes: Added @0no-co/graphql.web, gql-ast, appstash, inquirerer, and nested-obj as devDependencies in server-test — these are ORM/CLI runtime deps needed by the child process.

Review & Testing Checklist for Human

  • Hardcoded buildAnimalsTable() object (lines 100–205): This manually mirrors the simple-seed animals schema. Verify the field names, types, inflection keys (especially orderByType: 'AnimalOrderBy'), and query names match what introspection actually produces. If the codegen's expected Table shape evolves, this will silently generate wrong code.
  • Output structure parsing (raw.data?.animals ?? raw): Tests assume the CLI prints the raw ORM execute() result as JSON. Verify this matches the actual handleList/handleFindFirst output format. The fallback chain could mask shape mismatches.
  • Hardcoded UUID in Test 3: Asserts node.id === 'a0000001-0000-0000-0000-000000000001' — tied to simple-seed/test-data.sql. Confirm this ID exists and won't change.
  • resolveNodePaths() pnpm discovery: Walks require.resolve() paths to find all intermediate node_modules dirs for pnpm strict isolation. Verify this works in CI (which may have a different pnpm version or hoisting config).

Recommended test plan: Run cd graphql/server-test && pnpm test -- --testPathPattern cli-e2e --verbose locally and in CI to confirm all 5 tests pass. Also verify the existing test suite still passes (pnpm test).

Notes

  • The pnpm-lock.yaml diff is large but is purely formatting changes (single-line vs multi-line resolution objects) from a lockfile refresh — no dependency version changes.
  • The graphile-cache ERROR log during teardown (PostGraphile instance has been released) is pre-existing in other server-test suites and is harmless.

Link to Devin session: https://app.devin.ai/sessions/c92c3a11450342f8875625a60fa1be28
Requested by: @pyramation

Tests generated CLI commands (codegen → transpile → execute) against a
running PostgreSQL database with a real GraphQL server.

- Uses ts.transpileModule to strip types without resolving imports
- Uses async spawn (not execFileSync) to keep event loop unblocked
- Sets up appstash context pointing at test server endpoint
- Resolves NODE_PATH for pnpm's strict module isolation

5 focused corner-case tests:
1. Paginated list with --where (dot-notation) + --fields
2. Cursor-based forward pagination (--after)
3. find-first with --where.name.equalTo
4. Combined --where + --orderBy + --fields
5. Empty result set handling
@devin-ai-integration
Copy link
Copy Markdown
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