CtrlK
BlogDocsLog inGet started
Tessl Logo
PluginPublic

testland/graphql-subscription-test-author

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.

Quality

90%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide
SecuritybySnyk

Passed

No findings from the security scan

Overview
Quality
Evals
Security
Files

lifecycle-and-close-codes.mdreferences/

Connection lifecycle and close codes

Protocol close codes (graphql-ws)

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:

CodeMeaning
4400Bad request / invalid message
4401Unauthorized (no ConnectionInit before timeout)
4403Forbidden (server onConnect returned false)
4408Connection initialisation timeout
4409Subscriber already exists for that id
4429Too many initialisation requests

Lifecycle assertion (graphql-ws)

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']);

SKILL.md

tile.json