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…
от testland★ 18 звёзд на GitHubОб этом скилле
graphql-subscription-test-author
Overview
Per the GraphQL October 2021 spec (section 6.3, blocked by Cloudflare Turnstile - cite by stable ID "GraphQL October 2021 spec, Section 6.3: Subscription"), a subscription operation must: select a single root field, return an event stream, and emit one result per event. Each emitted result is executed independently against the schema, exactly like a query.
This skill covers testing the transport and resolver layers for subscriptions. The two most common Node.js transports are:
- graphql-ws - WebSocket subprotocol
"graphql-ws"(per the-guild.dev/graphql/ws) - graphql-sse - HTTP Server-Sent Events (per the-guild.dev/graphql/sse)
Both expose an identical async-iterator surface via client.iterate(),
making the same test patterns portable across transports.
When to use
- Writing tests for subscription resolvers (pubsub trigger, filter, error).
- Asserting connection lifecycle: handshake, auth rejection, protocol close.
- Verifying auth-on-connect:
connectionParams(WS) orauthenticatecallback (SSE) reject unauthenticated clients before any event is sent. - Integration-testing that event-stream shape matches the schema contract.
Distinct scope vs. sibling skills:
apollo-server-testscovers queries/mutations viaexecuteOperation; its Limitations section explicitly notes "Doesn't test subscriptions over WS."graphql-yoga-testscovers Yoga'syoga.fetch()path; subscription tests there go through Yoga's own plugin hooks, not graphql-ws/sse directly.graphql-yoga-tests(references/mercurius.md) andhasura-teststarget those specific runtimes.
How to use
- Install the transport client(s) plus the test runner (
graphql-ws+ws, orgraphql-sse, alongsidegraphqlandjest). - Start the server on
port: 0inbeforeAllso parallel suites each get a free OS-assigned port;dispose()the runner andclose()the server inafterAll. - Create a client with
createClientand drive the subscription throughclient.iterate(), pushing eachevent.datainto an array;breakonce the expected count arrives to close the stream. - Assert the emitted sequence and shape against the schema contract, checking
errorsisundefinedbefore readingdata. - Add auth-on-connect tests: reject a missing / invalid token (close code
4403for WS,401for SSE) and accept a valid one. - Add a resolver-isolation test with
graphqlsubscribe()+pubsub.publish(...)to cover trigger / filter / error logic without a transport. - Run under an extended
testTimeoutand--forceExitin CI so open sockets never hang the runner.
Authoring
Install
# WS transport
npm install --save-dev graphql-ws ws @types/ws
# SSE transport
npm install --save-dev graphql-sse
# Shared test utilities
npm install --save-dev graphql jest ts-jest
Server setup
Full server bootstraps for both transports (graphql-ws over ws, graphql-sse over
Node http), including the port: 0 free-port pattern, are in
references/transport-server-setup.md.
Basic subscription test (graphql-ws)
Per the-guild.dev/graphql/ws/get-started:
both queries and subscriptions use client.iterate(), which returns an
async iterator.
import { createClient } from 'graphql-ws';
describe('greetings subscription', () => {
let wss: ReturnType<typeof startWsServer>;
let client: ReturnType<typeof createClient>;
beforeAll(() => {
wss = startWsServer();
const addr = wss.wss.address() as { port: number };
client = createClient({ url: `ws://localhost:${addr.port}/graphql` });
});
afterAll(async () => {
client.dispose();
await wss.dispose();
wss.wss.close();
});
it('streams three greetings then completes', async () => {
const results: unknown[] = [];
const sub = client.iterate({ query: 'subscription { greetings }' });
for await (const event of sub) {
results.push(event.data);
if (results.length === 3) break; // break closes the stream
}
expect(results).toEqual([
{ greetings: 'Hi' },
{ greetings: 'Bonjour' },
{ greetings: 'Hola' },
]);
});
});
Basic subscription test (graphql-sse)
Per the-guild.dev/graphql/sse/get-started:
import { createClient } from 'graphql-sse';
it('receives events over SSE', async () => {
const { server, url } = startSseServer();
const client = createClient({ url });
const results: unknown[] = [];
const sub = client.iterate({ query: 'subscription { greetings }' });
for await (const event of sub) {
results.push(event.data);
if (results.length === 1) break;
}
expect(results[0]).toEqual({ greetings: 'Hi' });
server.close()
Установить graphql-subscription-test-author в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл 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.
Как установить скилл graphql-subscription-test-author?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл graphql-subscription-test-author запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic