Built-in plugins
Plugins extend Apollo Server's functionality by performing custom operations in response to certain events. These events correspond to individual phases of the GraphQL request lifecycle, and to the lifecycle of Apollo Server itself.
Certain Apollo Server features are provided as built-in plugins that are exported from apollo-server-core
(or another library that's distributed with apollo-server
). Apollo Server installs certain plugins automatically, but you can also install them manually to override their default settings. See each plugin's documentation for details.
You can also create custom plugins.
List of built-in plugins
Name | Library | Description |
---|---|---|
Usage reporting | apollo-server-core | Gathers helpful operation usage data and reports it to Apollo Studio for visualization, alerting, and more. |
Schema reporting | apollo-server-core | Automatically reports the server's schema to Apollo Studio on startup to enable schema history and up-to-date metrics. |
Inline trace | apollo-server-core | Used primarily by federated subgraphs to include operation trace data in responses to the gateway. |
Cache control | apollo-server-core | Calculates caching behavior for operation responses. |
Landing page (multiple) | apollo-server-core | Handle displaying a default or custom landing page at Apollo Server's base URL. |
Response cache | apollo-server-plugin-response-cache | Caches operation responses in a back-end store (in-memory, Redis, etc.) |
Installing plugins
You can install a plugin that isn't installed by default (or customize a default plugin) by providing a plugins
configuration option to the ApolloServer constructor, like so:
1import { ApolloServer } from "apollo-server";
2import {
3 ApolloServerPluginUsageReporting,
4 ApolloServerPluginLandingPageLocalDefault
5} from "apollo-server-core";
6
7const server = new ApolloServer({
8 typeDefs,
9 resolvers,
10 csrfPrevention: true,
11 cache: "bounded",
12 plugins: [
13 // Sets a non-default option on the usage reporting plugin
14 ApolloServerPluginUsageReporting({
15 sendVariableValues: { all: true },
16 }),
17 ApolloServerPluginLandingPageLocalDefault({ embed: true }), // recommended
18 ],
19});