# @as-integrations/express5

> An Apollo Server integration for use with Express v5

Latest version **1.1.2** (published 2025-07-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @as-integrations/express5
pnpm add @as-integrations/express5
yarn add @as-integrations/express5
bun add @as-integrations/express5
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2025-07-17 |
| First published | 2025-05-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 144.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Apollo |
| Maintainers | michael-watson, trevor.scheer, glasser, apollo-bot |

## Links

- npm: https://www.npmjs.com/package/@as-integrations/express5
- Repository: https://github.com/apollo-server-integrations/apollo-server-integration-express5
- Issues: https://github.com/apollo-server-integrations/apollo-server-integration-express5/issues
- npm.io page: https://npm.io/package/@as-integrations/express5

## Recent versions

- 1.1.2 (latest) — 2025-07-17
- 1.1.0-alpha.0 (alpha) — 2025-06-06
- 1.1.1 — 2025-07-07
- 1.1.0 — 2025-06-07
- 2.0.0-alpha.1 — 2025-06-02
- 2.0.0-alpha.0 — 2025-06-02
- 1.0.0 — 2025-05-09

## README

# Apollo Server Integration for Express v5

## **Introduction**

This package integrates Apollo Server v4 with version 5 of the Express web framework, by exporting a middleware that executes GraphQL operations.

It is identical to the middleware exported at `@apollo/server/express5` from the core `@apollo/server` v4 package, updated to support Express v5 instead of Express v4.

## **Requirements**

- **[Node.js v20](https://nodejs.org/)** or later
- **[Express v5](https://expressjs.com/)**; see `@as-integrations/express4` for Express v4 support
- **[Apollo Server v4](https://www.apollographql.com/docs/apollo-server/)**

## **Installation**

```bash
npm install @apollo/server graphql express@5 @as-integrations/express5 cors
```

## **Usage**

Set up [Express](https://expressjs.com/) & [Apollo Server](https://www.apollographql.com/docs/apollo-server/) like you usually would, and then connect the two by using the `expressMiddleware` middleware:

```typescript
import { ApolloServer } from '@apollo/server';
import { expressMiddleware } from '@as-integrations/express5';
import { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer';
import express from 'express';
import http from 'http';
import cors from 'cors';
import { typeDefs, resolvers } from './schema';

interface MyContext {
  token?: string;
}

// Required logic for integrating with Express
const app = express();
// Our httpServer handles incoming requests to our Express app.
// Below, we tell Apollo Server to "drain" this httpServer,
// enabling our servers to shut down gracefully.
const httpServer = http.createServer(app);

const server = new ApolloServer<MyContext>({
  typeDefs,
  resolvers,
  plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],
});
// Ensure we wait for our server to start
await server.start();

// Set up our Express middleware to handle CORS, body parsing,
// and our expressMiddleware function.
app.use(
  '/',
  cors<cors.CorsRequest>(),
  express.json(),
  // expressMiddleware accepts the same arguments:
  // an Apollo Server instance and optional configuration options
  expressMiddleware(server, {
    context: async ({ req }) => ({ token: req.headers.token }),
  }),
);

await new Promise<void>((resolve) =>
  httpServer.listen({ port: 4000 }, resolve),
);
console.log(`🚀 Server ready at http://localhost:4000/`);
```

Note: **You must call and await `server.start()` before using the integration.**

---
_Source: https://npm.io/package/@as-integrations/express5 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
