Skip to content

Ability to dynamically add/remove topics to/from asyncIterator #256

Open
@dimatillck

Description

@dimatillck

Hi, I wonder if there is a place for such functionality in this library.
What I'm trying to achieve is to be able to do something like that:

const SOMETHING_CHANGED_TOPIC = 'something_changed';
const SOMETHING_OTHER_CHANGED_TOPIC = 'something_other_changed';

export const resolvers = {
  Subscription: {
    anythingChanged: {
      subscribe: () => {
        const asyncIterator = pubsub.asyncIterator(SOMETHING_CHANGED_TOPIC);
        
        subscribeToInternalEvent('internal_event', (event) => {
          if (event.shouldSubscribeToSomethingOther) {
            asyncIterator.subscribe(SOMETHING_OTHER_CHANGED_TOPIC);
          }

          if (event.shouldUnsubscribeFromSomethingOther) {
            asyncIterator.unsubscribe(SOMETHING_OTHER_CHANGED_TOPIC);
          }
        });

        return asyncIterator;
      },
    },
  },
}

I have some implementation of this feature and I can create a PR to continue the discussion if there is a place for this feature in this library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions