Use when GraphQL subscriptions need tests over graphql-ws (WebSocket) or graphql-sse: subscribing through the async iterator, asserting event shape and order, connection lifecycle and close codes, auth on connect and pubsub triggers. Queries and mutations belong to the server test skills.
90%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
Both transports expose an identical async-iterator surface via client.iterate(),
so the same test patterns are portable once the server is up.
Per the-guild.dev/graphql/ws/get-started:
import { useServer } from 'graphql-ws/use/ws';
import { WebSocketServer } from 'ws';
import { schema } from './schema';
export function startWsServer(port = 0) {
const wss = new WebSocketServer({ port });
const dispose = useServer({ schema }, wss);
return { wss, dispose };
}Use port: 0 so the OS assigns a free port - parallel-test safe.
Per the-guild.dev/graphql/sse/get-started:
import { createServer } from 'http';
import { createHandler } from 'graphql-sse/lib/use/http';
import { schema } from './schema';
export function startSseServer() {
const handler = createHandler({ schema });
const server = createServer((req, res) => {
if (req.url === '/graphql/stream') return handler(req, res);
res.writeHead(404).end();
});
server.listen(0);
const { port } = server.address() as { port: number };
return { server, url: `http://localhost:${port}/graphql/stream` };
}