graphql-ws

Zero-dependency server and client implementing the GraphQL over WebSocket Protocol

Library
npm
v6.2.1
1,871stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
77/100Good
Development Activity68
Maintenance84
Community56
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture85
Code Quality82
Innovation78
Learning Curve68

graphql-ws is a coherent, zero-dependency implementation of the GraphQL over WebSocket Protocol, providing both a server and a client that speak the same well-specified subprotocol for running GraphQL subscriptions, queries, and mutations over a single WebSocket connection. It ships adapters for popular runtimes (ws, uWebSockets.js, Bun, Deno, crossws) and frameworks (Express, Fastify, Apollo, Relay), replacing the older, deprecated subscriptions-transport-ws with a lazy, lifecycle-aware, and fully protocol-compliant alternative.

Maintained by The Guild, it is widely adopted across the GraphQL ecosystem as the de facto standard for WebSocket-based subscriptions, with first-class TypeScript types and an auto-generated protocol document describing every message exchanged between client and server.

What You Get

  • A protocol-compliant WebSocket client (createClient) with lazy connection, retry/backoff, and both Promise and async-iterator subscription APIs
  • A transport-agnostic server (makeServer) that you plug into any WebSocket implementation via a thin adapter
  • Ready-made adapters for ws, uWebSockets.js, Bun, Deno, crossws, and @fastify/websocket
  • A fully specified, versioned GraphQL over WebSocket Protocol document (PROTOCOL.md) so client and server implementations stay interoperable
  • Zero runtime dependencies — graphql itself is the only peer dependency

Common Use Cases

  • Adding real-time GraphQL subscriptions to an existing Node.js or edge WebSocket server
  • Building a GraphQL client that needs queries, mutations, and subscriptions over one persistent connection
  • Migrating off the deprecated subscriptions-transport-ws protocol to a maintained, spec-compliant alternative
  • Powering GraphQL subscriptions in serverless/edge runtimes like Bun, Deno, or Cloudflare via crossws

Under The Hood

Architecture - The library splits cleanly into three modules: common.ts defines the wire protocol (message types, close codes, and the graphql-transport-ws subprotocol name), client.ts implements a lazy, retrying WebSocket client exposing both a Promise-based subscribe and an async-iterable interface built on top of a small internal observable implementation, and server.ts implements a transport-agnostic makeServer that accepts any object satisfying a minimal WebSocket-like interface and drives the connection lifecycle (connection_init, ack, subscribe, next, complete) per the protocol spec. Runtime-specific adapters under src/use/ (ws, uWebSockets.js, Bun, Deno, crossws, @fastify/websocket) are thin shims translating each runtime’s WebSocket API into the shape makeServer expects, which is what lets one core implementation run everywhere. Tech Stack - Written in TypeScript with zero runtime dependencies; graphql is the sole peer dependency, and runtime-specific packages (ws, crossws, @fastify/websocket, uWebSockets.js) are optional peers pulled in only for the adapters actually used. The build uses pkgroll/Rollup to emit dual ESM/CJS output with matching .d.ts/.d.cts type declarations, and the package is tested with Vitest. Code Quality - The tests/ directory has dedicated suites for common protocol logic, the client, the server, and each runtime adapter (common.test.ts, client.test.ts, server.test.ts, use.test.ts), exercising the full connection lifecycle including error and close-code paths. Source files use extensive TSDoc comments (@category annotations feed the auto-generated TypeDoc site) and strict TypeScript (@tsconfig/strictest), giving strong compile-time guarantees around the message protocol’s discriminated unions. API Design - The public surface is small and consistent: createClient/subscribe on the client side and makeServer plus a runtime adapter on the server side, mirroring the same message vocabulary on both ends. Documentation is auto-generated from source comments and published to a dedicated docs site, and the standalone PROTOCOL.md gives implementers of other languages/runtimes an exact reference, which keeps the getting-started surface small despite the protocol’s completeness.

Used by 11 apps in this directory

TypeScript
96%
Other

Amplication

Developer Tools · AI Code Assistants · Automation

16,011

Create production-ready backend services with your organization's standards baked in — generating NestJS, Prisma, and GraphQL code that you own and control.

View details
60
Repo Health
84
Technical
60
Dependency
Built with
TypeScript96%
Updated 2 months ago
Go
54%
Apache 2.0

Authgear

Authentication

2,028

Open-source, self-hostable authentication platform with passkeys, biometric login, SSO, MFA, and GraphQL admin API — a full Auth0/Clerk/Firebase alternative for SaaS and mobile apps.

View details
88
Repo Health
81
Technical
68
Dependency
Built with
Go54%
HTML25%
TypeScript18%
Updated 3 days ago
PHP
78%
Other

Craft CMS

CMS

3,605

A developer-first PHP CMS with clean-slate content modeling, auto-generated GraphQL API, and a four-tier edition system that scales from solo projects to enterprise deployments.

View details
96
Repo Health
83
Technical
62
Dependency
Built with
PHP78%
JavaScript14%
Updated yesterday
TypeScript
81%
Other

Directus

CMS · Low Code Platforms

37,783

Connect any SQL database and get instant REST and GraphQL APIs, a visual management Studio, and a native MCP server for AI agents — free for most organizations.

View details
92
Repo Health
82
Technical
76
Dependency
Built with
TypeScript81%
Vue18%
Updated 3 days ago
TypeScript
99%
MIT

GraphQL Hive

Developer Tools · Devops · Monitoring

484

Open-source GraphQL schema registry and observability platform with breaking change detection, federation support, and CI/CD integration for teams of any size.

View details
89
Repo Health
81
Technical
69
Dependency
Built with
TypeScript99%
Updated 2 days ago
TypeScript
99%
MIT

KeystoneJS

CMS · Developer Tools

9,969

The superpowered headless CMS for developers built with GraphQL and React

View details
91
Repo Health
81
Technical
64
Dependency
Built with
TypeScript99%
Updated 5 days ago
TypeScript
88%
Apache 2.0

Medplum

Developer Tools · Databases · Authentication

2,657

An open-source, FHIR-native healthcare platform that gives developers a compliant backend, authentication, a React component library, and serverless bots to build clinical applications in weeks instead of years.

View details
93
Repo Health
90
Technical
72
Dependency
Built with
TypeScript88%
MDX10%
Updated yesterday
HTML
36%

OpenPanel

Hosting Control Panel · Devops

743

Docker-powered web hosting control panel that gives every user a fully isolated environment with dedicated web server, database, and networking — VPS-grade security on shared hardware.

View details
81
Repo Health
75
Technical
63
Dependency
Built with
HTML36%
Go32%
TypeScript25%
Updated yesterday
TypeScript
88%
MIT

Plasmic

CMS · Low Code Platforms · No Code Platforms

6,993

The open-source visual builder that lets teams design React apps and websites with drag-and-drop while integrating seamlessly with your codebase.

View details
81
Repo Health
78
Technical
64
Dependency
Built with
TypeScript88%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search