API Reference

Apollo Server

Spec-compliant GraphQL server for Node.js with schema-first resolvers, context, plugins, and standalone or Express hosting.

Official Documentation ↗
CompatibilityThis documentation covers version Apollo Server 5 (@apollo/server); legacy apollo-server is end-of-life and integrations moved to @as-integrations packages. Check the official docs for the latest API surface.

Installation

npmnpm install @apollo/server graphql
pnpmpnpm add @apollo/server graphql
yarnyarn add @apollo/server graphql

Methods

Apollo Server executes GraphQL queries and mutations over HTTP. It provides a spec-compliant pipeline, a plugin system for caching, tracing, and lifecycle hooks, and adapters for standalone hosting or an existing Node web framework.

Overview

The server is constructed with typeDefs and resolvers, then started before it accepts traffic. Context is built per request and passed to resolvers, which is where authentication and data loaders belong. Apollo Studio reporting is opt-in through environment variables, and introspection can be disabled independently of the schema.

Installation

Install @apollo/server with graphql as a peer dependency. For Express hosting, also install the matching integration package, @as-integrations/express5 for Express 5 or @as-integrations/express4 for Express 4. Apollo Server 5 requires a current Node.js LTS release and uses ESM-friendly packages; the legacy apollo-server package should not be used for new work.

Core API walkthrough

new ApolloServer accepts typeDefs, resolvers, and plugins. server.start prepares the schema and must be awaited. startStandaloneServer boots an HTTP server for development with an optional context factory. expressMiddleware mounts the same server inside Express, and server.executeOperation runs a query directly for integration tests through response.body.

Pitfalls

Calling executeOperation before start fails. The Express integration must come from the @as-integrations package, because Apollo Server 5 no longer ships expressMiddleware from the core package. Deep context objects can leak request state between calls if cached globally. Introspection is enabled by default, so disable it explicitly in production if schema privacy matters.

Verification

Run a query through executeOperation and assert both data and the absence of errors. Mount the same server in Express and confirm POST /graphql returns JSON with the expected content type. Check that an invalid query returns a validation error rather than a 500, and verify the context factory receives the authorization header.

FAQ

Is the apollo-server package still maintained?
No. The unscoped apollo-server package is end-of-life. Current releases are published as @apollo/server, and existing projects should migrate imports, context typing, and framework integrations.
Why is expressMiddleware not exported from @apollo/server?
Apollo Server 5 moved framework integrations into separate packages. Import expressMiddleware from @as-integrations/express5 for Express 5, or @as-integrations/express4 for Express 4, and install the package explicitly.
How do I test resolvers without starting a server?
Call server.executeOperation with a query and optional contextValue after awaiting server.start(). Read response.body, which is a single result or an incremental stream, and assert on data or errors.