Absinthe subscriptions: Unsubscribe from all topics

Hi all,

How can I unsubscribe from all topics (Absinthe subscriptions) upon logout?

Frontend (React & Apollo):

const logoutMutation = gql`
  mutation {
    logout
  }
`;

Backend (Phoenix & Absinthe):

def logout(user_id) do
  ...
  unsubscribe_all_topics(user_id)
  ...
end
def unsubscribe_all_topics(user_id) do
???
end

Subscriptions exist only as long as the websocket is alive. You can either track the various subscription handles you get back from the subscribe call, and call unsubscribe with each of them, or you can simply disconnect the websocket connection you sent the subscriptions over, and that will also automatically terminate all of them.

4 Likes

@benwilson512 Thanks a lot for your assistance!:smile: