# QuerySubscription


```
@SubclassOptInRequired
interface QuerySubscription<Data : Any?, Variables : Any?>
```

<br />

*** ** * ** ***

A facility to subscribe to a query to be notified of updates to the query's data when the query is executed.

### Realtime updates (May 2026)

Starting with SDK version 17.3.0 (Firebase BoM 34.14.0, May 2026) query subscriptions gained support for realtime updates. See [Get real-time updates from SQL Connect](https://firebase.google.com/docs/sql-connect/realtime) for details.

Prior to SDK version 17.3.0, updates were *not* realtime, and were *not* pushed from the server. Instead, the notifications were sent whenever the query was explicitly executed by calling `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/dataconnect/QueryRef#execute()`.

### Realtime updates setup and requirements

In order for the server to send realtime updates, caching *must* be configured in your `connector.yaml` file. For example:

```kotlin
connectorId: coolstuff
authMode: PUBLIC
generate:
  kotlinSdk:
    package: com.mycompany.coolstuff
    clientCache:
      maxAge: 1h
```

Without this setting the server simply will not send realtime updates.

Then, in the `.gql` files for your connector that define the operations, you will need to add `@refresh` directives to the queries for which you want realtime updates. Some very simple queries will automatically gain an implicit `@refresh` directive; however, even mildly complex queries will need the directive added in order to get realtime updates on clients.

### Safe for concurrent use

All methods and properties of `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/dataconnect/QuerySubscription` are thread-safe and may be safely called and/or accessed concurrently from multiple threads and/or coroutines.

### Not stable for inheritance

The `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/dataconnect/QuerySubscription` interface is *not* stable for inheritance in third-party libraries, as new methods might be added to this interface or contracts of the existing methods can be changed.

## Summary

| ### Public functions |
|---|---|
| `operator https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/dataconnect/QuerySubscription#equals(kotlin.Any)(other: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html?)` Compares this object with another object for equality, using the `===` operator. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/dataconnect/QuerySubscription#hashCode()()` Calculates and returns the hash code for this object. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/dataconnect/QuerySubscription#toString()()` Returns a string representation of this object, useful for debugging. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://firebase.google.com/docs/reference/kotlin/com/google/firebase/dataconnect/QuerySubscriptionResult<Data, Variables>>` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/dataconnect/QuerySubscription#flow()` A cold flow that collects the query results as they become available. |
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/dataconnect/QueryRef<Data, Variables>` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/dataconnect/QuerySubscription#query()` The query whose results this object subscribes. |

## Public functions

### equals

```
operator fun equals(other: Any?): Boolean
```

Compares this object with another object for equality, using the `===` operator.

The implementation of this method simply uses referential equality. That is, two instances of `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/dataconnect/QuerySubscription` compare equal using this method if, and only if, they refer to the same object, as determined by the `===` operator.

| Parameters |
|---|---|
| `other: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html?` | The object to compare to this for equality. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `other === this` |

### hashCode

```
fun hashCode(): Int
```

Calculates and returns the hash code for this object.

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | the hash code for this object. |

### toString

```
fun toString(): String
```

Returns a string representation of this object, useful for debugging.

The string representation is *not* guaranteed to be stable and may change without notice at any time. Therefore, the only recommended usage of the returned string is debugging and/or logging. Namely, parsing the returned string or storing the returned string in non-volatile storage should generally be avoided in order to be robust in case that the string representation changes.

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | a string representation of this object, which includes the class name and the values of all public properties. |

## Public properties

### flow

```
val flow: Flow<QuerySubscriptionResult<Data, Variables>>
```

A cold flow that collects the query results as they become available.

Starting with SDK version 17.3.0 (Firebase BoM 34.14.0, May 2026) query subscriptions gained support for realtime updates. See `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/dataconnect/QuerySubscription` for details.

### query

```
val query: QueryRef<Data, Variables>
```

The query whose results this object subscribes.