Releases: enisdenjo/graphql-ws
Releases · enisdenjo/graphql-ws
v5.16.0
v5.15.0
v5.14.3
v5.14.2
v5.14.1
v5.14.0
5.14.0 (2023-06-22)
Features
Examples
Use the client
import { createClient } from 'graphql-ws';
const client = createClient({
url: 'ws://localhost:4000/graphql',
});
// query
(async () => {
const query = client.iterate({
query: '{ hello }',
});
const { value } = await query.next();
expect(value).toEqual({ hello: 'world' });
})();
// subscription
(async () => {
const subscription = client.iterate({
query: 'subscription { greetings }',
});
for await (const event of subscription) {
expect(event).toEqual({ greetings: 'Hi' });
// complete a running subscription by breaking the iterator loop
break;
}
})();
v5.13.1
v5.13.0
5.13.0 (2023-05-12)
Features
Examples
Start the server with Bun
import { makeHandler, handleProtocols } from 'graphql-ws/lib/use/lib/bun';
import { schema } from './previous-step';
Bun.serve({
fetch(req, server) {
const [path, _search] = req.url.split('?');
if (!path.endsWith('/graphql')) {
return new Response('Not Found', { status: 404 });
}
if (req.headers.get('upgrade') != 'websocket') {
return new Response('Upgrade Required', { status: 426 });
}
if (handleProtocols(req.headers.get('sec-websocket-protocol') || '')) {
return new Response('Bad Request', { status: 404 });
}
if (!server.upgrade(req)) {
return new Response('Internal Server Error', { status: 500 });
}
return new Response();
},
websocket: makeHandler({ schema }),
port: 4000,
});
console.log('Listening to port 4000');
Start the server with Deno
import { serve } from 'https://deno.land/std/http/mod.ts';
import {
makeHandler,
GRAPHQL_TRANSPORT_WS_PROTOCOL,
} from 'https://esm.sh/graphql-ws/lib/use/deno';
import { schema } from './previous-step.ts';
const handler = makeHandler({ schema });
serve(
(req: Request) => {
const [path, _search] = req.url.split('?');
if (!path.endsWith('/graphql')) {
return new Response('Not Found', { status: 404 });
}
if (req.headers.get('upgrade') != 'websocket') {
return new Response('Upgrade Required', { status: 426 });
}
const { socket, response } = Deno.upgradeWebSocket(req, {
protocol: GRAPHQL_TRANSPORT_WS_PROTOCOL,
idleTimeout: 12_000,
});
handler(socket);
return response;
},
{ port: 4000 },
);