API Reference: Subscription Callback Plugin
This document covers the usage of the subscription callback plugin for use in Apollo Federation with GraphOS Router. For more information about the protocol itself, see the subscription callback protocol.
⚠️ Note: The subscription callback protocol is currently in preview. Breaking changes might be introduced during the preview period.
Using the plugin
This article documents the options for the ApolloServerPluginSubscriptionCallback
plugin, which you can import from @apollo/server/plugin/subscriptionCallback
.
This plugin enables your GraphQL server to respond to subscription operations using the subscription callback protocol. GraphOS Router uses this protocol to execute subscription operations and receive updates at a URL specified by the router.
This feature can only be enabled by providing an ApolloServerPluginSubscriptionCallback
instance to your ApolloServer
constructor:
1import { ApolloServer } from '@apollo/server';
2import { ApolloServerPluginSubscriptionCallback } from '@apollo/server/plugin/subscriptionCallback';
3
4const server = new ApolloServer({
5 typeDefs,
6 resolvers,
7 plugins: [
8 ApolloServerPluginSubscriptionCallback(),
9 ],
10});
Caveats
The subscription plugin implementation inherently bypasses Apollo Server's request lifecycle. This means that certain plugin hooks (notably executionDidStart
and willResolveField
) will not be called when handling callback subscription requests or when sending subscription events. There is currently no metrics or tracing support for callback subscriptions.
Options
Name / Type |
Description |
---|---|
| Optionally configure the heartbeat interval in milliseconds. The default is 5 seconds, which is the interval that GraphOS Router expects. Lengthening this interval may cause GraphOS Router to invalidate existing subscriptions frequently and is not recommended. You may want to shorten this interval if you have latency issues between your GraphQL Server and GraphOS Router. |
| Optionally provide a Logger instance to capture logs from the plugin. |
| This plugin uses the async-retry module to retry failed requests to GraphOS Router. You can optionally provide an Options object to configure the retry behavior. The configuration options for async-retry can be found in the README.The default configuration provided by this plugin is:TypeScript
Options object to the plugin:TypeScript
|