Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): Async iterator for subscriptions #486

Merged
merged 3 commits into from Jun 22, 2023
Merged

feat(client): Async iterator for subscriptions #486

merged 3 commits into from Jun 22, 2023

Conversation

enisdenjo
Copy link
Owner

The iterate method on the client allows async iteration over the subscription events.

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;
  }
})();

TODO

@github-actions
Copy link

💻 Website Preview

The latest changes are available as preview in: https://3311b3ee.graphql-ws.pages.dev

@enisdenjo enisdenjo merged commit fb4b967 into master Jun 22, 2023
13 checks passed
@enisdenjo enisdenjo deleted the iterate branch June 22, 2023 12:07
enisdenjo pushed a commit that referenced this pull request Jun 22, 2023
# [5.14.0](v5.13.1...v5.14.0) (2023-06-22)

### Features

* **client:** Async iterator for subscriptions ([#486](#486)) ([fb4b967](fb4b967))
@enisdenjo
Copy link
Owner Author

🎉 This PR is included in version 5.14.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@enisdenjo enisdenjo added the released Has been released and published label Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Has been released and published
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant