5.14.0 (2023-06-22)
Features
- client: Async iterator for subscriptions (#486) (fb4b967)
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;
}
})();