apollographql / apollographql/graphql-subscriptions

Ability to dynamically add/remove topics to/from asyncIterator

Open
#256 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.6k
Forks
129
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

Research direction

No file or test is named. Start by reviewing the pubsub.asyncIterator entry point and the dynamic subscribe/unsubscribe behavior described in the example, then compare the proposed implementation with the library's current API. Done would require an agreed feature scope and corresponding validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.