# How to UnSubscribe GraphQL Apollo Subscription in Kotlin

**URL:** <https://community.apollographql.com/t/how-to-unsubscribe-graphql-apollo-subscription-in-kotlin/5529>\
**Category:** Client SDKs\
**Tags:** kotlin\
**Created:** [January 20, 2023, 9:32am UTC](https://community.apollographql.com/t/how-to-unsubscribe-graphql-apollo-subscription-in-kotlin/5529 "2023-01-20T09:32:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pramit\_jain](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/pramit_jain/32/3068_2.png) [@Pramit\_jain](https://community.apollographql.com/u/Pramit_jain)\
**Post date:** [January 20, 2023, 9:32am UTC](https://community.apollographql.com/t/how-to-unsubscribe-graphql-apollo-subscription-in-kotlin/5529/1 "2023-01-20T09:32:14Z")

</div>

We are trying to start subscription in onCreate() method in MainActivity and we are able to connect to graphQL subscription which is connected successfully and giving proper response. Below is the code how we connect to graphQL subscription.

```
return ApolloClient.Builder()
         .httpServerUrl("https://dqt-customer-test.azurewebsites.net/graphql")
         .webSocketServerUrl("wss://dqt-customer-test.azurewebsites.net/graphql")
         .webSocketReopenWhen { e, attempt ->
            if (e is WebSocketReconnectException) {
                true
            } else {
                attempt < 3
            }
      }
        .build()

```

How to unsubscribe this WebSocket connection when I move to next screen.

we followed the Apollo Client Documentation for applying the subscription but for closing the connection we couldn’t find any method.

> **[Authenticate your operations](https://www.apollographql.com/docs/kotlin/advanced/authentication)**

---

<div class="post-metadata">

**Author:** ![watson](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/watson/32/2053_2.png) [@watson](https://community.apollographql.com/u/watson)\
**Post date:** [January 20, 2023, 10:00pm UTC](https://community.apollographql.com/t/how-to-unsubscribe-graphql-apollo-subscription-in-kotlin/5529/2 "2023-01-20T22:00:45Z")

</div>

Hopefully [these docs](https://www.apollographql.com/docs/kotlin/essentials/subscriptions#terminating-a-subscription) help more, but if you cancel the coroutine it will terminate a subscription. When no subscription is active, the WebSocket is closed after a configurable timeout.
