You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/api/plugin/cache-control.mdx
+22-24Lines changed: 22 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,62 +5,58 @@ api_reference: true
5
5
6
6
## Using the plugin
7
7
8
-
This API reference documents the `ApolloServerPluginCacheControl` plugin.
8
+
This article documents the options for the `ApolloServerPluginCacheControl` plugin, which you can import from `@apollo/server/plugin/cacheControl`.
9
9
10
-
This plugin enables your GraphQL server to specify a cache policy at the field level, either statically in your schema with the `@cacheControl` directive, or dynamically in your resolvers via the `info.cacheControl` API. It also by default sets the `cache-control` HTTP response header. This page is a reference for the options available in configuring the plugin; more background and examples are available in [the caching documentation](../../performance/caching/).
10
+
This plugin enables your GraphQL server to specify a cache policy at the field level, either statically in your schema with the `@cacheControl` directive, or dynamically in your resolvers via the `info.cacheControl` API. It also sets the `cache-control` HTTP response header by default. See [Server-side caching](../../performance/caching/) for more information and examples.
11
+
12
+
> To use the `@cacheControl` directive, you must first [define it in your schema](../../performance/caching/#in-your-schema-static).
11
13
12
14
Apollo Server installs this plugin by default in all servers, with its default configuration. You typically do not have to install this plugin yourself; you only need to do so if you want to provide non-default configuration.
13
15
14
-
If you want to configure this plugin, import it from the `apollo-server-core` package and pass it to your `ApolloServer` in the `plugins` array:
16
+
If you want to configure the `ApolloServerPluginCacheControl` plugin, import it and pass it to your `ApolloServer` constructor's `plugins` array:
(The plugin does not have much of an effect on your app if you do not use the `@cacheControl` directive or use the `info.cacheControl` API; there might be a very slight performance improvement from disabling the plugin if you do not use it.)
57
+
</MultiCodeBlock>
62
58
63
-
Note that in Apollo Server 3, the cache control plugin does *not* define the `@cacheControl` directive for you; if you want to use the directive, you must [define the `@cacheControl` directive in your schema](../..//performance/caching/#in-your-schema-static).
59
+
The plugin doesn't affect your app much if you don't use the `@cacheControl` directive or the `info.cacheControl` API. If you don't currently use it, there might be a very slight performance improvement from disabling the plugin.
64
60
65
61
## Options
66
62
@@ -83,7 +79,9 @@ Note that in Apollo Server 3, the cache control plugin does *not* define the `@c
83
79
</td>
84
80
<td>
85
81
86
-
By default, root fields and fields that return a composite type (object, interface, or union) are considered to be uncacheable (`maxAge` 0) unless a cache hint is explicitly provided via `@cacheControl` or `info.cacheControl`. You can set this option to make the default `maxAge` for these larger than 0; this will effectively cause all requests to be be cacheable. (This option was popular in Apollo Server 2 largely as a workaround for the problem solved by the [`@cacheControl(inheritMaxAge: true)`](../../performance/caching/#in-your-schema-static) directive argument; consider using `inheritMaxAge` instead of `defaultMaxAge` in Apollo Server 3.) You can read more about [`defaultMaxAge` in the caching documentation](../../performance/caching/#default-maxage).
82
+
By default, root fields and fields that return a composite type (object, interface, or union) are considered to be uncacheable (`maxAge` 0) unless a cache hint is explicitly provided via `@cacheControl` or `info.cacheControl`. You can set this option to make the default `maxAge` for these larger than 0; this will effectively cause all requests to be cacheable.
83
+
84
+
This option was popular in Apollo Server 2 as a workaround for the problem solved by the [`@cacheControl(inheritMaxAge: true)`](../../performance/caching/#in-your-schema-static) directive argument. See [Default `maxAge`](../../performance/caching/#default-maxage) for more details.
Copy file name to clipboardExpand all lines: docs/source/api/plugin/drain-http-server.mdx
+34-31Lines changed: 34 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,59 +5,62 @@ api_reference: true
5
5
6
6
## Using the plugin
7
7
8
-
This API reference documents the `ApolloServerPluginDrainHttpServer` plugin.
8
+
This article documents the options for the `ApolloServerPluginDrainHttpServer` plugin, which you can import from `@apollo/server/plugin/drainHttpServer`.
9
9
10
-
This plugin is designed for use with [`apollo-server-express` and other framework-specific packages](../../integrations/middleware/#all-supported-packages) which are built on top of [Node `http.Server`s](https://nodejs.org/api/http.html#http_class_http_server). It is highly recommended that you use this plugin with packages like `apollo-server-express` if you want your server to shut down gracefully.
10
+
This plugin is designed for use with `expressMiddleware` and other frameworkintegrationsbuilt on top of [Node `http.Server`s](https://nodejs.org/api/http.html#http_class_http_server). **We highly recommend** using this plugin to ensure your server shuts down gracefully.
11
11
12
-
You do not need to explicitly use this plugin with the batteries-included `apollo-server` package: that package automatically uses this plugin internally.
12
+
> You do not need to use this plugin with the `startStandaloneServer` function; it automatically handles server draining.
13
13
14
-
When you use this plugin, Apollo Server will drain your HTTP server when you call the `stop()` method (which is also called for you when the `SIGTERM` and `SIGINT` signals are received, unless disabled with the [`stopOnTerminationSignals` constructor option](../apollo-server/#stoponterminationsignals)). Specifically, it will:
14
+
When you use this plugin, Apollo Server will drain your HTTP server when you call the `stop()` method (which is also called for you when the `SIGTERM` and `SIGINT` signals are received, unless disabled with the [`stopOnTerminationSignals` constructor option](../apollo-server/#stoponterminationsignals)).
15
15
16
-
* Stop listening for new connections
17
-
* Close idle connections (i.e., connections with no current HTTP request)
18
-
* Close active connections whenever they become idle
19
-
* Wait for all connections to be closed
20
-
* After a grace period, if any connections remain active, forcefully close them.
16
+
Specifically, it will:
21
17
22
-
This plugin is exported from the `apollo-server-core` package. It is tested with `apollo-server-express`, `apollo-server-koa`, and `apollo-server-fastify`. (If you're using Hapi, you should instead use the `ApolloServerPluginStopHapiServer` plugin exported from the `apollo-server-hapi` package.)
18
+
- Stop listening for new connections
19
+
- Close idle connections (i.e., connections with no current HTTP request)
20
+
- Close active connections whenever they become idle
21
+
- Wait for all connections to be closed
22
+
- After a grace period, if any connections remain active, forcefully close them.
23
23
24
-
Here's a basic example of how to use it with Express. See the [framework integrations docs](../../integrations/middleware/) for examples of how to use it with other frameworks.
0 commit comments