balanceUpdates method

Future<Stream<QueryResult<Object?>>> balanceUpdates(
  1. BalanceOrigin origin
)

Subscribes to Balance updates of the authenticated MyUser in the provided BalanceOrigin.

Authentication

Mandatory.

Initialization

Once this subscription is initialized completely, it immediately emits SubscriptionInitialized.

If nothing has been emitted for a long period of time after establishing this subscription (while not being completed), it should be considered as an unexpected server error. This fact can be used on a client side to decide whether this subscription has been initialized successfully.

Result

Initial Balance will be emitted after SubscriptionInitialized. This allows to skip calling balance before establishing this subscription.

Completion

Infinite.

Completes requiring a re-subscription when:

  • Authenticated Session expires (SESSION_EXPIRED error is emitted).
  • An error occurs on the server (error is emitted).
  • The server is shutting down or becoming unreachable (unexpectedly completes after initialization).

Idempotency

Emits only changed Balance against the previously emitted one, so a client side is expected to handle all the updates idempotently using the same logic.

Implementation

Future<Stream<QueryResult>> balanceUpdates(BalanceOrigin origin) async {
  Log.debug('balanceUpdates(${origin.name})', '$runtimeType');

  final variables = BalanceUpdatesArguments(origin: origin);
  return client.subscribe(
    SubscriptionOptions(
      operationName: 'BalanceUpdates',
      document: BalanceUpdatesSubscription(variables: variables).document,
      variables: variables.toJson(),
    ),
  );
}