Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The motivation for this PR is to clean up what we've got such that the good stuff can be used as a library by other projects that want to add graphql-ws over WebSocket-Over-Http support to their apps that use apollo-server.
Library APIs
We're trying to expose an API that is as close as possible to some patterns documented by apollo-server itself. As such, I made these two new files based on those patterns.
PubSubEngine
you're using withEpcpPubSubMixin
so that calls toPubSubEngine#publish
also get published to the GRIP server via EPCP. Notably, creating this mixin requires aGraphQLSchema
instance so that the graphql-ws message published to subscriptions can have the right fields added.Other API Ideas
apollo-server-api
. You basically pass all your config to anApolloServer
constructor and then callApolloServer#listen
on the instance and things just magically work (unlikeHttpServer#listen
,ApolloServer#listen()
returns a promise of both a graphql HTTP url anda graphql subscriptions URL that WebSocket conections should be made to).
apollo-server-express-api
I did above is what your customers probably use in the real world. Since I did that one already, and I'm already deviating from thesubscription-server-api
we emailed about, I wanted to pause here and check in before spending time on this.Other Changes
There are lots of lines changed in here, mostly hygiene:
FanoutGraphqlExpressServer
that really had nothing to do with Fanout or this particular demo. I moved them into their own files in directories that indicate a logically separate moduleEpcpPubSubMixin
can wrap any graphql PubSubEngine to forward any publishes to a URI via EPCPWebSocket
API. This module is for graphql-ws utilities that aren't coupled to any particular transport APIAcceptAllGraphqlSubscriptionsMessageHandler
is a function that responds to graphlq-ws messages such that all incoming connections are acked/startedApolloSubscriptionServerOptions
- this is useful if you want to be able to do what apollo-server-express'sApolloServer#installSubscriptionHandlers
does but using an underlying SubscriptionServer that is not the one from subscription-transport-wsGraphqlWebSocketOverHttpConnectionListener
basically translates graphql-ws to WebSocket-Over-Http. This is the thing that currently encapsulates the logic to always respond to incoming graphQl subscriptions by creating a Grip-Channel equal to the subscription name. This will need to change for more complicated/parameterized subscriptionsGraphqlWsOverWebSocketOverHttpExpressMiddleware
can be added as middleware to any Express app to automatically accept all incoming graphql-ws connections that come in over WebSocket-Over-Http