Skip to content

Conversation

@pyramation
Copy link
Contributor

@pyramation pyramation commented Jan 11, 2026

Summary

This PR adds a new @constructive-io/playwright-test package that extends @constructive-io/graphql-test to provide an actual HTTP server for Playwright and other E2E testing frameworks. The package creates isolated test databases and starts a GraphQL server configured with enableServicesApi: false to bypass domain/subdomain routing.

Key exports:

  • getConnectionsWithServer() - Creates DB connections and HTTP server, returns server URL for Playwright
  • getConnectionsWithServerObject() - Object-based query API variant
  • getConnectionsWithServerUnwrapped() - Throws on GraphQL errors instead of returning them
  • createTestServer() - Low-level server creation utility

Also exports middleware functions from @constructive-io/graphql-server for use in testing packages.

Updates since last revision

  • Added Playwright test that verifies HTTP server responds to GraphQL introspection queries and direct query function works alongside HTTP server
  • Fixed graphile middleware to handle undefined opts.graphile properties using optional chaining (prevents "Cannot read properties of undefined" errors when graphile options aren't provided)
  • Removed brittle ?? fallbacks in getEnvOptions call - now only passes anonRole/roleName when authRole is explicitly provided

Review & Testing Checklist for Human

  • Test data queries - The included test only covers introspection queries ({ __typename }). Data queries (e.g., allUsers) were not tested because they returned errors during development. Verify that actual table queries work correctly with your schemas.
  • Review graphile middleware change - The fix in graphql/server/src/middleware/graphile.ts adds optional chaining for opts.graphile?.appendPlugins, opts.graphile?.graphileBuildOptions, and opts.graphile?.overrideSettings. Ensure this doesn't break existing consumers that rely on these being defined.
  • Verify teardown cleanup - Confirm that calling teardown() properly stops the HTTP server and cleans up the database without leaving orphaned connections

Recommended test plan:

const { server, query, teardown } = await getConnectionsWithServer({
  schemas: ['your_schema'],
  authRole: 'your_role'
}, [seed.sqlfile(['/path/to/your/schema.sql'])]);

// Test HTTP request with actual data query
const response = await fetch(server.graphqlUrl, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ query: '{ allYourTable { nodes { id } } }' })
});
// Verify response contains expected data

await teardown();

Notes

Requested by: Dan Lynch (@pyramation)
Devin session: https://app.devin.ai/sessions/a583a9da700a4feca3985c559d33e51f

This package extends @constructive-io/graphql-test to provide an actual HTTP
server for Playwright and other E2E testing frameworks. It creates isolated
test databases and starts a GraphQL server with enableServicesApi: false to
bypass domain routing.

Key features:
- getConnectionsWithServer() - creates DB connections and HTTP server
- getConnectionsWithServerObject() - object-based query API variant
- getConnectionsWithServerUnwrapped() - throws on GraphQL errors
- createTestServer() - low-level server creation utility

Also exports middleware functions from graphql-server for testing packages.
@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

Let getEnvOptions handle defaults instead of using brittle ?? fallbacks.
Only pass anonRole/roleName when authRole is explicitly provided.
- Add @playwright/test as dev dependency
- Create Playwright test that verifies HTTP server responds to GraphQL queries
- Test both HTTP requests and direct query function
- Fix graphile middleware to handle undefined opts.graphile properties
- Add test SQL file for creating test schema
@pyramation pyramation merged commit f23f6c2 into main Jan 11, 2026
36 checks passed
@pyramation pyramation deleted the devin/1768102491-playwright-test branch January 11, 2026 15:49
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.

2 participants