Authors GraphQL subscription resolver test suites over graphql-ws (WebSocket) and graphql-sse (Server-Sent Events) transports: subscribe to event streams via the async-iterator API, assert emitted data shape and sequence, verify connection lifecycle and protocol close codes, and validate auth-on-connect (connectionParams / authenticate callback) plus resolver-level pubsub trigger logic. Use for real-time subscription operations; not for queries or mutations - for those use apollo-server-tests, graphql-yoga-tests, or mercurius-tests.
75
94%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Per the-guild.dev/graphql/ws/docs,
the on option in ClientOptions accepts event-keyed callbacks. Protocol
close codes are defined by the graphql-ws spec:
| Code | Meaning |
|---|---|
| 4400 | Bad request / invalid message |
| 4401 | Unauthorized (no ConnectionInit before timeout) |
| 4403 | Forbidden (server onConnect returned false) |
| 4408 | Connection initialisation timeout |
| 4409 | Subscriber already exists for that id |
| 4429 | Too many initialisation requests |
const events: string[] = [];
const client = createClient({
url,
connectionParams: { token: 'valid' },
on: {
connecting: () => events.push('connecting'),
connected: () => events.push('connected'),
closed: () => events.push('closed'),
error: () => events.push('error'),
},
});
const sub = client.iterate({ query: 'subscription { greetings }' });
await sub.next(); // wait for first event - connection must be open
await sub.return?.(); // graceful close via iterator return
// Allow close event to fire
await new Promise((r) => setTimeout(r, 50));
expect(events).toEqual(['connecting', 'connected', 'closed']);