Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement callback subscription protocol in new plugin ApolloServerPluginSubscriptionCallback #7617

Merged
merged 21 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions .changeset/cuddly-lemons-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@apollo/server': minor
---

Introduce new `ApolloServerPluginSubscriptionCallback` plugin. This plugin implements the [subscription callback protocol](https://github.com/apollographql/router/blob/dev/dev-docs/callback_protocol.md) which is used by Apollo Router. This feature implements subscriptions over HTTP via a callback URL which Apollo Router registers with Apollo Server. This feature is currently in preview and is subject to change.

You can enable callback subscriptions like so:
```ts
import { ApolloServerPluginSubscriptionCallback } from '@apollo/server/plugin/subscriptionCallback';
import { ApolloServer } from '@apollo/server';

const server = new ApolloServer({
// ...
plugins: [
ApolloServerPluginSubscriptionCallback(),
],
});
```

Note that there is currently no tracing or metrics mechanism in place for callback subscriptions. Additionally, this plugin "intercepts" callback subscription requests and bypasses some of Apollo Server's internals. The result of this is that certain plugin hooks (notably `executionDidStart` and `willResolveField`) will not be called when handling callback subscription requests or when sending subscription events.

For more information on the subscription callback protocol, visit the docs:
https://www.apollographql.com/docs/router/executing-operations/subscription-callback-protocol/
trevor-scheer marked this conversation as resolved.
Show resolved Hide resolved
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"eslint-plugin-import": "2.27.5",
"express": "4.18.2",
"graphql": "16.7.1",
"graphql-subscriptions": "2.0.0",
"graphql-tag": "2.12.6",
"jest": "29.5.0",
"jest-config": "29.5.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@
"import": "./dist/esm/plugin/schemaReporting/index.js",
"require": "./dist/cjs/plugin/schemaReporting/index.js"
},
"./plugin/subscriptionCallback": {
trevor-scheer marked this conversation as resolved.
Show resolved Hide resolved
"types": {
"require": "./dist/cjs/plugin/subscriptionCallback/index.d.ts",
"default": "./dist/esm/plugin/subscriptionCallback/index.d.ts"
},
"import": "./dist/esm/plugin/subscriptionCallback/index.js",
"require": "./dist/cjs/plugin/subscriptionCallback/index.js"
},
"./plugin/usageReporting": {
"types": {
"require": "./dist/cjs/plugin/usageReporting/index.d.ts",
Expand Down
8 changes: 8 additions & 0 deletions packages/server/plugin/subscriptionCallback/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@apollo/server/plugin/subscriptionCallback",
"type": "module",
"main": "../../dist/cjs/plugin/subscriptionCallback/index.js",
"module": "../../dist/esm/plugin/subscriptionCallback/index.js",
"types": "../../dist/esm/plugin/subscriptionCallback/index.d.ts",
"sideEffects": false
}