OfflineFirstWithGraphqlRepository class abstract
Ensures the remoteProvider is a GraphqlProvider
. All requests to and
from the remoteProvider pass through a seperate SQLite queue. If the app
is unable to make contact with the remoteProvider, the queue automatically retries in
sequence until it receives a response.
OfflineFirstWithGraphqlRepository should accept a type argument such as <_RepositoryModel extends OfflineFirstWithGraphqlModel>, however, this causes a type bound error on runtime. The argument should be reintroduced with a future version of the compiler/analyzer.
Constructors
-
OfflineFirstWithGraphqlRepository({bool? autoHydrate, required GraphqlProvider graphqlProvider, required SqliteProvider sqliteProvider, String? loggerName, MemoryCacheProvider? memoryCacheProvider, required Set<
Migration> migrations, required GraphqlRequestSqliteCacheManager offlineRequestManager})
Properties
- autoHydrate → bool
-
Refetch results in the background from remote source when any request is made.
Defaults to
false
.finalinherited - hashCode → int
-
The hash code for this object.
no setterinherited
- logger → Logger
-
User for low-level debugging. The logger name can be defined in the default constructor;
it defaults to
OfflineFirstRepository
.finalinherited - memoryCacheProvider → MemoryCacheProvider
-
The first data source to speed up otherwise taxing queries. Only caches specified models.
finalinherited
- migrationManager → MigrationManager
-
finalinherited
- offlineRequestQueue ↔ GraphqlOfflineRequestQueue
-
latefinal
- remoteProvider → GraphqlProvider
-
The type declaration is important here for the rare circumstances that
require interfacting with
GraphqlProvider
's client directly.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sqliteProvider → SqliteProvider
-
The local data source utilized before every operation.
finalinherited
-
subscriptions
→ Map<
Type, Map< Query?, StreamController< >List< >OfflineFirstWithGraphqlModel> > -
finalinherited
Methods
-
applyPolicyToQuery(
Query? query, {OfflineFirstDeletePolicy? delete, OfflineFirstGetPolicy? get, OfflineFirstUpsertPolicy? upsert}) → Query? -
As some links may consume
OfflineFirstGraphqlPolicy
from the request's context, this adds the policy to theproviderArgs#context
-
delete<
TModel extends OfflineFirstWithGraphqlModel> (TModel instance, {Query? query, OfflineFirstDeletePolicy policy = OfflineFirstDeletePolicy.optimisticLocal}) → Future< bool> - Remove a model from SQLite and the remoteProvider
-
exists<
TModel extends OfflineFirstWithGraphqlModel> ({Query? query}) → Future< bool> -
Check if a
TModel
is accessible locally. First checks if there's a matching query in memoryCacheProvider and then check sqliteProvider. Does not query remoteProvider. -
get<
TModel extends OfflineFirstWithGraphqlModel> ({OfflineFirstGetPolicy policy = OfflineFirstGetPolicy.awaitRemoteWhenNoneExist, Query? query, bool seedOnly = false}) → Future< List< TModel> > -
Load association from SQLite first; if the
TModel
hasn't been loaded previously, fetch it from remoteProvider and hydrate SQLite. For available query providerArgs seeremoteProvider#get
SqliteProvider.get
. -
getAssociation<
TModel extends RepositoryModel> (Query query) → Future< List< TModel> ?> -
Used exclusively by the
OfflineFirstAdapter
. If there are no results, returnsnull
.inherited -
getBatched<
TModel extends RepositoryModel> ({int batchSize = 50, OfflineFirstGetPolicy policy = OfflineFirstGetPolicy.awaitRemoteWhenNoneExist, Query? query, bool seedOnly = false}) → Future< List< TModel> > -
Get all results in series of
batchSize
s (defaults to50
). Useful for large queries or remote results.inherited -
hydrate<
TModel extends OfflineFirstWithGraphqlModel> ({bool deserializeSqlite = true, Query? query}) → Future< List< TModel> > - Fetch and store results from remoteProvider into SQLite and the memory cache.
-
initialize(
) → Future< void> -
Prepare the environment for future repository functions. It is recommended to call this
method within a
StatefulWidget
'sinitState
to ensure it is only invoked once. It is not automatically invoked. -
migrate(
) → Future< void> - Update SQLite structure with only new migrations.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifySubscriptionsWithLocalData<
TModel extends RepositoryModel> ({bool notifyWhenEmpty = true}) → Future< void> -
Iterate through subscriptions after an upsert and notify any subscribe listeners.
inherited
-
reset(
) → Future< void> -
Destroys all local records - specifically, memoryCache and sqliteProvider's
data sources.
inherited
-
storeRemoteResults<
TModel extends RepositoryModel> (List< TModel> models, {bool shouldNotify = true}) → Future<List< TModel> > -
Save response results to SQLite.
inherited
-
subscribe<
TModel extends OfflineFirstWithGraphqlModel> ({OfflineFirstGetPolicy policy = OfflineFirstGetPolicy.awaitRemoteWhenNoneExist, Query? query}) → Stream< List< TModel> > - Listen for streaming changes from the remoteProvider. Data is returned in complete batches. get is invoked on the memoryCacheProvider and sqliteProvider following an upsert invocation. For more, see notifySubscriptionsWithLocalData.
-
toString(
) → String -
A string representation of this object.
inherited
-
upsert<
TModel extends OfflineFirstWithGraphqlModel> (TModel instance, {OfflineFirstUpsertPolicy policy = OfflineFirstUpsertPolicy.optimisticLocal, Query? query}) → Future< TModel> - Send a model to remoteProvider and hydrate.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited