@as-integrations/express5

Apollo Server integration middleware for Express v5

Library
npm
v1.1.2
3stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
33/100Needs Attention
Development Activity48
Maintenance32
Community12
Maturity40
Momentum0

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
68/100Good
Architecture65
Code Quality75
Innovation45
Learning Curve85

@as-integrations/express5 provides expressMiddleware(), a small adapter function that turns an already-started Apollo Server instance into a standard express.RequestHandler, purpose-built for Express v5’s updated body-parsing and routing internals. It handles translating Express’s request/response objects into Apollo Server’s HTTPGraphQLRequest format, including header normalization, error responses for missing body-parser middleware, and context construction from the request/response pair.

The package is one of several framework-specific integrations published under the @as-integrations scope by the Apollo Server integrations organization, each targeting a single web framework (Express 4, Express 5, Koa, Fastify, etc.) rather than trying to abstract over all of them, so consumers only depend on the adapter matching their actual server framework.

What You Get

  • expressMiddleware() returning a ready-to-mount express.RequestHandler
  • Automatic translation of Express request/response objects into Apollo Server’s HTTPGraphQLRequest/response shape
  • Typed context function support (ExpressContextFunctionArgument) for injecting request-scoped GraphQL context
  • Built-in validation that body-parser middleware ran before the GraphQL handler, with a clear error message if not
  • Express v5-specific compatibility (updated body-parser defaults, routing changes) not present in the Express v4 integration

Common Use Cases

  • Mounting a GraphQL API built with Apollo Server onto an existing Express v5 application
  • Migrating an Express v4 + Apollo Server app to Express v5 without switching GraphQL server implementations
  • Adding request-scoped context (auth user, request ID) to Apollo Server resolvers from Express middleware state
  • Running GraphQL alongside existing REST routes in the same Express v5 server instance

Under The Hood

Architecture - the entire package is a single 117-line src/index.ts module exporting one function, expressMiddleware(), which asserts the Apollo Server instance has started, builds a context function (defaulting to an empty object context), and returns an async Express handler that validates body-parser ran, converts the Express req/res into Apollo Server’s HTTPGraphQLRequest via HeaderMap, calls server.executeHTTPGraphQLRequest(), and writes the resulting headers/status/body back onto the Express response. Tech Stack - TypeScript with dual ESM/CJS build outputs (tsc --build), depending on @apollo/server and @apollo/utils.withrequired as peer-ish dependencies, packaged with changesets for versioning and Renovate for dependency updates. Code Quality - src/__tests__/integration.test.ts and expressSpecific.test.ts cover both generic Apollo Server integration behavior and Express-5-specific edge cases (body-parser detection, header handling), run under Jest with ESLint/Prettier/cspell enforced in CI. API Design - the API is deliberately minimal: one overloaded function whose TypeScript signatures force a context option only when the context type isn’t BaseContext, so integrating GraphQL into an Express app requires a single app.use('/graphql', expressMiddleware(server)) call.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search