Skip to content

Commit

Permalink
feat(subscriptions): enable passing WebSocket.Server instead… (#2314)
Browse files Browse the repository at this point in the history
Permit passing a `WebSocket.Server` instance into `installSubscriptionHandlers`.
  • Loading branch information
jedwards1211 authored Apr 22, 2020
1 parent 1e694eb commit b67bd13
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
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

0 comments on commit b67bd13

Please sign in to comment.