Does Apollo Server's createTestClient execute custom Express middleware during testing?
24K reputation · 16 Jun 2024, 19:13 UTC
When writing integration tests for an Apollo Server schema, the goal is to verify that resolver logic works alongside any custom Express middleware (such as request‑level logging, CORS handling, or rate‑limiting) without relying on production credentials or making real network calls. The createTestClient utility from @apollo/server/testing provides an in‑process GraphQL executor, but its documentation notes that it bypasses the HTTP layer, leaving it unclear whether Express‑based middleware attached to the server instance is actually invoked during a test query.
Because the test client does not recreate the full Express request/response cycle, developers must decide whether to trust that middleware behavior is covered by these tests or to supplement them with separate middleware‑focused tests.
- Does
createTestClientinvoke Express middleware registered on the Apollo Server instance? - If it does not, what is the recommended way to test middleware behavior while still avoiding production credentials?
- Are there any configuration options or patterns that enable middleware execution within the test client?