Docs
Launch GraphOS Studio
Since 4.9.0

API Reference: Subscription callback plugin


This covers the usage of the callback plugin for use in with . 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 to respond to subscription operations using the subscription callback protocol. Apollo Router uses this protocol to execute subscription 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:

import { ApolloServer } from '@apollo/server';
import { ApolloServerPluginSubscriptionCallback } from '@apollo/server/plugin/subscriptionCallback';
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [ApolloServerPluginSubscriptionCallback()],
});
import { ApolloServer } from '@apollo/server';
import { ApolloServerPluginSubscriptionCallback } from '@apollo/server/plugin/subscriptionCallback';
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [ApolloServerPluginSubscriptionCallback()],
});

Caveats

The subscription plugin implementation inherently bypasses '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
heartbeatIntervalMs

number

Optionally configure the heartbeat interval in milliseconds. The default is 5 seconds, which is the interval that Apollo Router expects. Lengthening this interval may cause Apollo Router to invalidate existing frequently and is not recommended. You may want to shorten this interval if you have latency issues between your and Apollo Router.

logger

Logger

Optionally provide a Logger instance to capture logs from the plugin.

retry

Options

This plugin uses the async-retry module to retry failed requests to Apollo 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:

{
retries: 5,
minTimeout: 100,
maxTimeout: 1000,
}

These defaults can be overridden (and other options can be provided) by passing an Options object to the plugin:

new ApolloServer({
plugins: [
ApolloServerPluginSubscriptionCallback({
retry: {
retries: 3,
minTimeout: 1000,
maxTimeout: 5000,
randomize: true,
},
}),
],
// ...
})
Previous
Landing pages
Next
Creating plugins
Edit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company