-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement callback subscription protocol in new plugin `ApolloServerP…
…luginSubscriptionCallback` (#7617) This PR creates a new plugin for Apollo Server which implements the new [subscription callback protocol](https://www.apollographql.com/docs/router/executing-operations/subscription-callback-protocol/). While the plugin approach works, it does have a couple notable pitfalls. I see this as a good first step towards enabling people to use it today. The nature of this implementation is to skip execution in Apollo Server altogether, which means the execution internals are bypassed. This means that some plugin hooks are skipped - notably `executionDidStart/End` and `willResolveField` (for field-level instrumentation) when resolving these types of operations. Fortunately, most of the logic is captured in the `SubscriptionManager` class. The plugin mostly just wraps it, and Apollo Server should be able to integrate it when we choose to.
- Loading branch information
1 parent
98eb29e
commit 4ff81ca
Showing
7 changed files
with
2,602 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.