@ilijanl/graphql-ws-graphqless
v5.14.1
Published
Coherent, zero-dependency, lazy, simple, based on graphql websocket protocol, compliant server and client
Downloads
2
Maintainers
Readme
Graphql-Ws-gqless
Getting started
Install
yarn add @ilijanl/graphql-ws-graphqless
A fork of graphql-ws. This package is meant to be used for custom executions based on graphql-transport-ws protocol. If used for graphql, go with original graphql-ws package.
All credits go to @enisdenjo
Create own subscription server
import { WebSocketServer } from 'ws'; // yarn add ws
// import ws from 'ws'; yarn add ws@7
// const WebSocketServer = ws.Server;
import { useServer } from '@ilijanl/graphql-ws-graphqless/lib/use/ws';
import { schema } from './previous-step';
const server = new WebSocketServer({
port: 4000,
path: '/path',
});
useServer(
{
createSubscription: () => {
const iter = (async function* () {
for (const hi of ['Hi', 'Bonjour', 'Hola', 'Ciao', 'Zdravo']) {
yield { greetings: hi };
}
})();
return {
start: async function (emit) {
for await (const l of iter) {
await emit({ data: { greetings: l } });
}
},
stop: () => {
iter.return(undefined);
},
};
},
},
server,
);
console.log('Listening to port 4000');