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

feat(subscriptions): enable passing WebSocket.Server instead of HttpServer. #2314

Merged
merged 3 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The version headers in this history reflect the versions of Apollo Server itself

> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the the appropriate changes within that release will be moved into the new section.

- _Nothing yet! Stay tuned._
- Allow passing a `WebSocket.Server` to `ApolloServer.installSubscriptionHandlers`. [PR #2314](https://github.com/apollographql/apollo-server/pull/2314)

### v2.12.0

Expand Down
14 changes: 9 additions & 5 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
ExecutionParams,
} from 'subscriptions-transport-ws';

import WebSocket from 'ws';

import { formatApolloErrors } from 'apollo-server-errors';
import {
GraphQLServerOptions,
Expand Down Expand Up @@ -667,7 +669,7 @@ export class ApolloServerBase {
}
}

public installSubscriptionHandlers(server: HttpServer) {
public installSubscriptionHandlers(server: HttpServer | WebSocket.Server) {
if (!this.subscriptionServerOptions) {
if (this.config.gateway) {
throw Error(
Expand Down Expand Up @@ -742,10 +744,12 @@ export class ApolloServerBase {
},
keepAlive,
},
{
server,
path,
},
server instanceof WebSocket.Server
? server
: {
server,
path,
},
);
}

Expand Down