1

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 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Please have in mind that subscriptions-transport-ws is not actively maintained: „The subscriptions-transport-ws library is not being actively maintained. It is recommended that you use the graphql-ws library instead. For details read the GraphQL over WebSockets announcement“

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.