GraphQL over WebSocket Protocol compliant server and client.
Coherent, zero-dependency, lazy, simple,Getting started
Install
$ yarn add graphql-transport-ws
Create a GraphQL schema
; // Construct a schema, using GraphQL schema language; // The roots provide resolvers for each GraphQL operation;
Start the server
;;; ; createServer , ,; server.listen443;
Use the client
; ; // query; // subscription;
Recipes
Client usage with Promise
; ; // use;
Client usage with Observable
;// or;// or;// or;// or any other lib which implements Observables as per the ECMAScript proposal: https://github.com/tc39/proposal-observable ; ; ; // ⏱ subscription.unsubscribe;
Client usage with Relay
;; ; // yes, both fetch AND subscribe handled in one implementation ;
Client usage with Apollo
;; ;
Client usage in Node
; // yarn add ws;; ; // consider other recipes for usage inspiration
Server usage with Express GraphQL
;;;;;; // create express and middleware;app.use'/graphql', graphqlHTTP; // create a http server using express; server.listen443,;
Server usage with console logging
;;; ; createServer , ,; server.listen443;
Server usage on a multi WebSocket server
;;;;;; ; /** * Two websocket servers on different paths: * - `/wave` sends out waves * - `/graphql` serves graphql */;; // delegate upgrade requests to relevant destinationsserver.on'upgrade',; // wave on connectwaveWS.on'connection',; // serve graphqlcreateServer , graphqlWS,; server.listen443;
Server usage with custom static GraphQL arguments
;;; createServer , ,;
Server usage with custom dynamic GraphQL arguments and validation
;;; createServer , ,;
Server and client usage with persisted queries
// 🛸 server ;;; ; ; createServer , ,;
// 📺 client ; ; ;
Documentation
Check the docs folder out for TypeDoc generated documentation.
How does it work?
Read about the exact transport intricacies used by the library in the GraphQL over WebSocket Protocol document.
Want to help?
File a bug, contribute with code, or improve documentation? Read up on our guidelines for contributing and drive development with yarn test --watch
away!