query<T> method

Query<T> query<T>(
  1. QueryOptions<T> options
)

Returns or creates the cache entry for options.

Implementation

Query<T> query<T>(QueryOptions<T> options) {
  _requireKeyType<T>(options.key);
  final cached = queryCache.getAny(options.key.canonical);
  if (cached != null) {
    if (cached.dataType == T) {
      final existing = cached as Query<T>;
      existing.setOptions(options);
      return existing;
    }
    if (cached.dataType == dynamic && cached.options.query == null) {
      return adoptHydratedQuery(cached, options);
    }
    throw _queryTypeConflict(options.key, cached.dataType, T);
  }
  final resolved = resolve(options);
  final created = Query<T>(
    client: this,
    cache: queryCache,
    options: resolved,
    sourceOptions: options,
  );
  queryCache.add(created);
  return created;
}