I have been following the docs for here and here to implement the subscriptions-transport-ws plugin. My big confusion is differentiating the graphql url for http:// and ws://. In the examples above it looks like ApolloServer is getting replaced by SubscriptionServer. But if I only want to use websockets in special circumstances, then don't I still need both? Or is SubscriptionServer handling both at once and doing some magic in the background which figures out which one to use based on whether or not a subscription is called?
1 Answer
apollo-server combines several tools such as: graphql-tools, graphql-subscriptions, graphql-upload, provide some custom errors, and use express.js web framework as its default web server implementation.
subscriptions-transport-ws is a GraphQL WebSocket server and client to facilitate GraphQL queries, mutations, and subscriptions over WebSocket.
subscriptions-transport-ws is an extension for GraphQL, and you can use it with any GraphQL client and server (not only Apollo).
So, ApolloServer is NOT replaced by SubscriptionServer.
Without using ApolloServer, you need to set up GraphQL HTTP server using express.js, graphqlExpress, graphiqlExpress, cors middlewares by yourself. Like this official sample does.
If you want to create a subscription server, you need to create HTTP server and pass it to SubscriptionServer constructor for initing and connecting WebSocket server to http