GraphQL over WebSocket, done by the book
Zero-dependency, lazy, simple, spec compliant server and client. graphql-ws is the reference implementation of the GraphQL over WebSocket protocol, with adapters for every popular WebSocket server. Part of the Hive ecosystem by The Guild.
- Spec compliant, as the reference implementation
- Server and client in one small library
- Adapters for ws, uWebSockets.js, Fastify, Bun and Deno
Resilient subscriptions, without the ceremony
- Spec compliantFully compliant with the GraphQL over WebSocket protocol, with strong authentication rules through an easy API and pings and pongs to measure latency and keep connections alive.
- Server and clientOne zero-dependency library ships both sides. Tree-shaking and module separation keep the bundle small, and smart retry strategies let you shape reconnection to your needs.
- Choose your serverReady-made handlers for ws, uWebSockets.js, @fastify/websocket, Bun, Deno and crossws, or plug the protocol-only server into any WebSocket implementation.
Subscribe in a few lines
Start a server on top of ws, then iterate over subscription events on the client with an async iterator; queries and mutations go through the same connection.
Get startedimport { createClient } from 'graphql-ws';
const client = createClient({
url: 'ws://localhost:4000/graphql',
});
const subscription = client.iterate({
query: 'subscription { greetings }',
});
for await (const event of subscription) {
console.log(event.data); // { greetings: 'Hi' }, { greetings: 'Bonjour' }, ...
}Learn more
Recipes
Short and concise code snippets for common use cases: Relay, urql, Apollo, auth, pings and pongs, persisted queries and more.
Browse the recipes →API reference
Every module, function, interface and type of the client, the server, the protocol messages and the server adapters.
API reference →Changelog
Every release and the changes it brought.
Changelog →
Discover the complete ecosystem of tools and libraries
Complete GraphQL Federation Stack
Our libraries to support all your GraphQL needs
Explore the Ecosystem