apollo-server README

The project's README from github.com/apollographql/apollo-server. As one markdown file: README.md.

@apollo/server

This @apollo/server package is new since Apollo Server 4. Previous major versions of Apollo Server used a set of package names starting with apollo-server, such as apollo-server, apollo-server-express, apollo-server-core, etc.

npm version Build Status Join the community


Announcement: Join 1000+ engineers at GraphQL Summit 2025 by Apollo for talks, workshops, and office hours. Oct 6-8, 2025 in San Francisco. Get your pass here ->


A TypeScript/JavaScript GraphQL server

Apollo Server is an open-source, spec-compliant GraphQL server that's compatible with any GraphQL client, including Apollo Client. It's the best way to build a production-ready, self-documenting GraphQL API that can use data from any source.

You can use Apollo Server as:

Apollo Server provides a simple API for integrating with any Node.js web framework or serverless environment. The @apollo/server package itself ships with a minimally-configurable, standalone web server which handles CORS and body parsing out of the box. Integrations with other environments are community-maintained.

Apollo Server provides:

Documentation

Full documentation for Apollo Server is available on our documentation site. This README shows the basics of getting a server running (both standalone and with Express), but most features are only documented on our docs site.

Getting started: standalone server

You can also check out the getting started guide in the Apollo Server docs for more details, including examples in both TypeScript and JavaScript.

Apollo Server's standalone server lets you get a GraphQL server up and running quickly without needing to set up an HTTP server yourself. It allows all the same configuration of GraphQL logic as the Express integration, but does not provide the ability to make fine-grained tweaks to the HTTP-specific behavior of your server.

First, install Apollo Server and the JavaScript implementation of the core GraphQL algorithms:

npm install @apollo/server graphql

Then, write the following to server.mjs. (By using the .mjs extension, Node lets you use the await keyword at the top level.)

import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';

// The GraphQL schema
const typeDefs = `#graphql
  type Query {
    hello: String
  }
`;

// A map of functions which return data for the schema.
const resolvers = {
  Query: {
    hello: () => 'world',
  },
};

const server = new ApolloServer({
  typeDefs,
  resolvers,
});

const { url } = await startStandaloneServer(server);
console.log(`🚀 Server ready at ${url}`);

Now run your server with:

node server.mjs

Open the URL it prints in a web browser. It will show Apollo Sandbox, a web-based tool for running GraphQL operations. Try running the operation query { hello }!

Getting started: Express middleware

Apollo Server's Express middleware lets you run your GraphQL server as part of an app built with Express, the most popular web framework for Node.

First, install Apollo Server, its Express middleware, the JavaScript implementation of the core GraphQL algorithms, Express, and the standard Express middleware package for CORS headers:

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

If using Typescript you may also need to install additional type declaration packages as development dependencies to avoid common errors when importing the above packages (i.e. Could not find a declaration file for module 'cors'):

npm install --save-dev @types/cors @types/express

Then, write the following to server.mjs. (By using the .mjs extension, Node lets you use the await keyword at the top level.)

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';

// The GraphQL schema
const typeDefs = `#graphql
  type Query {
    hello: String
  }
`;

// A map of functions which return data for the schema.
const resolvers = {
  Query: {
    hello: () => 'world',
  },
};

const app = express();
const httpServer = http.createServer(app);

// Set up Apollo Server
const server = new ApolloServer({
  typeDefs,
  resolvers,
  plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],
});
await server.start();

app.use(
  cors(),
  express.json(),
  expressMiddleware(server),
);

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

Now run your server with:

node server.mjs

Open the URL it prints in a web browser. It will show Apollo Sandbox, a web-based tool for running GraphQL operations. Try running the operation query { hello }!

apollo-server (apollographql/apollo-server)

web-server
Searching Database…

What is this?Apollo Server is an open-source, spec-compliant GraphQL server for Node.js that lets you build a production-ready, self-documenting GraphQL API from any data source, either standalone or plugged into frameworks like Express, Connect, Hapi, or Koa.
Is this a standalone server or a library I add to my app?It is an npm library (@apollo/server) you install into your own Node project. It ships a minimally-configurable standalone HTTP server out of the box, but it can also run as middleware inside an existing Express (or other) app.
How do I get a basic GraphQL server running?Install @apollo/server and the graphql package with npm, write your schema and resolvers in a server.mjs file, then run it with Node (the .mjs extension lets you use top-level await). Opening the printed URL shows Apollo Sandbox for testing queries like 'query { hello }'.
What do I need before I start?You need Node.js 20 or newer and npm 8.19.2+, plus the peer 'graphql' package for core GraphQL execution. For the Express integration you also need express and the cors middleware package.
Are the Connect, Hapi, and Koa integrations maintained by Apollo itself?No. Only the Express middleware ships directly with this project; integrations for Connect, Hapi, Koa and other environments are maintained by the community, not the core Apollo team.
What is Apollo Sandbox?Apollo Sandbox is a web-based GraphQL IDE that Apollo Server automatically serves at your server's URL, letting you run operations like 'query { hello }' directly from the browser without extra setup.
Can Apollo Server be used for GraphQL Federation?Yes. Besides running as a stand-alone server, it can act as the GraphQL server for a subgraph in a federated supergraph, or as the gateway that sits in front of a federated supergraph.
Why is it called @apollo/server instead of apollo-server?@apollo/server is the unified package introduced in Apollo Server 4, replacing the older split packages (apollo-server, apollo-server-express, apollo-server-core) that earlier major versions used.
Does it work with any GraphQL client?Yes, it is spec-compliant and built to be compatible with any GraphQL client, including but not limited to Apollo Client.
Size
136.6 MB
Stars
14K
Age
10y
Commits · 90 Days