⬡ GraphQL Advanced

What is GraphQL subscriptions with WebSocket protocol graphql-ws vs subscriptions-transport-ws?

Answer

Two WebSocket protocols for GraphQL subscriptions: subscriptions-transport-ws: the original library (by Apollo), using the graphql-ws (confusingly different from the library below) sub-protocol string. It is now deprecated and unmaintained. Known issues: connection problems, unclear error handling, protocol design issues. graphql-ws library: the modern, actively maintained replacement by Denis Badurina. Uses the graphql-transport-ws sub-protocol. Key improvements: clear connection lifecycle (Connected → Ping/Pong → Subscribe → Next/Error/Complete), proper error handling, lazy connection mode, reconnection support, and active maintenance. Apollo Client 3.5+ supports graphql-ws: const wsLink = new GraphQLWsLink(createClient({ url: 'ws://localhost:4000/subscriptions' }));. Server setup: useServer({ schema }, wsServer);. Always use graphql-ws for new projects. Migrate existing projects away from subscriptions-transport-ws.