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

WIP: Support for new graphql-js subscriptions support #60

Merged
merged 3 commits into from
May 14, 2017

Conversation

Urigo
Copy link
Contributor

@Urigo Urigo commented May 9, 2017

Background

Based on graphql-js with support for subscriptions (graphql/graphql-js#846) with AsyncIterator.

Changes

  • Removed most of the previous code.
  • Removed SubscriptionManager and it's execute logic.
  • PubSub remains the same, but with support for asyncIterator conversion.

Usage Examples

Simple Example

import { PubSub } from `graphql-subscriptions`;

const pubsub = new PubSub();

const resolvers = {
     Subscriptions: {
         commentAdded: {
              subscribe: () => pubsub.asyncIterator('newComment'),
         }
     }
}

pubsub.publish('newComment', { commentAdded: { ... });

Mapping Channels

Mapping channels is simpler now: the GraphQL subscriptions is not related to the PubSub events directly by name. That means that you can use any publication name you want - as long you use it as return value in your subscribe resolver.

Multiple Channels

Just like a single channels mapping, you can pass an array of channels names:

pubsub.asyncIterator(['newComment', 'updatedComment']),

Filters

Filters is important when using subscriptions, and in this new version, the filter is closer to the actual resolver implementation.
You can write your filter and use withFilter over your existing AsyncIterator:

const resolvers = {
  Subscription: {
    commentAdded: {
      subscribe: withFilter(pubsub.asyncIterator('commentAdded'), (payload, args) => {
        return payload.commentAdded.repository_name === args.repoFullName;
      }),
    },
  },
}

@Urigo Urigo merged commit 5fd95bf into master May 14, 2017
@leebyron
Copy link

As you write about using AsyncIterator - I think IxJS is a great resource for working with them.

@NeoPhi NeoPhi deleted the feature/new-graphql branch October 6, 2017 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants