QueryFilter typedef

QueryFilter = bool Function(String key, QoraState state, QoraOptions? lastOptions)

The central engine of Qora: manages queries, cache, deduplication, retries, reactive state, and network-aware pausing / reconnect replay.

Initialisation

// Minimal (all defaults)
final client = QoraClient();

// With custom configuration
final client = QoraClient(
  config: QoraClientConfig(
    defaultOptions: QoraOptions(
      staleTime: Duration(minutes: 5),
      retryCount: 2,
    ),
    debugMode: kDebugMode,
    maxCacheSize: 200,
    reconnectStrategy: ReconnectStrategy(maxConcurrent: 3),
  ),
);

One-shot fetch

final user = await client.fetchQuery<User>(
  key: ['users', userId],
  fetcher: () => api.getUser(userId),
);

Reactive stream

client.watchQuery<User>(
  key: ['users', userId],
  fetcher: () => api.getUser(userId),
  options: QoraOptions(refetchInterval: Duration(seconds: 30)),
).listen((state) {
  switch (state) {
    case Success(:final data):   updateUI(data);
    case Failure(:final error):  showError(error);
    default: {}
  }
});

Optimistic update

final snapshot = client.getQueryData<User>(['users', userId]);
client.setQueryData(['users', userId], optimisticUser);

try {
  await api.updateUser(userId, payload);
} catch (_) {
  client.restoreQueryData(['users', userId], snapshot);
}

Network awareness

Attach a ConnectivityManager (via QoraScope or directly) to enable:

// Exposed so QoraMutationBuilder can wire the offline queue.
final isOnline = client.isOnline;
final queue = client.offlineMutationQueue;

Predicate used by QoraClient.invalidateQueries to select cache entries.

Receives the string-serialised normalised key, the current state, and the lastOptions recorded from the most recent fetch (or null for entries that were pre-populated via initialData and never fetched).

// Invalidate every query whose key starts with 'users'.
client.invalidateQueries(
  filter: (key, state, opts) => key.startsWith('["users"'),
);

// Invalidate all stale queries that use a refetchInterval.
client.invalidateQueries(
  filter: (key, state, opts) => opts?.refetchInterval != null,
);

// Invalidate only currently-failing queries.
client.invalidateQueries(
  filter: (key, state, opts) => state is Failure,
);

Implementation

typedef QueryFilter = bool Function(
  String key,
  QoraState<dynamic> state,
  QoraOptions? lastOptions,
);