apollographql / apollographql/graphql-subscriptions

Proposal: unsubscribe field

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

Description

Currently there is a subscribe and a resolve field on resolvers.

I propose an unsubscribe field as well that can be used to release server resources.

There is currently no way to tell running processes that the subscription is no longer active to release the resources. An example is a memory heavy simulation system that is provisioned on subscribing and needs to be torn down when the client closes the connection.

```ts
Subscriptions: {
mySub: {
subscribe: () => AsyncIterator
resolve: payload => resolvedPayload
unsubscribe: () => void
}
}
```

An implementation would have the server create a stack of unsubscribe functions on the socket connection that it adds to on each subscription call. When the socket it closed, it would call each of those unsubscribe functions.

Contributor guide

Open the contributing guide

Research direction

Start by locating the subscription resolver and socket-connection lifecycle code; the issue names no specific files or tests. Read how subscribe and resolve are wired, then determine the cleanup lifecycle for multiple active subscriptions. Done means closed connections release all resources through the proposed unsubscribe behavior, with coverage for that lifecycle.

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
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.