brick_offline_first_with_graphql 3.2.0 copy "brick_offline_first_with_graphql: ^3.2.0" to clipboard
brick_offline_first_with_graphql: ^3.2.0 copied to clipboard

A Brick domain that routes data fetching through local providers before a GraphQL provider.

brick_offline_first_with_graphql workflow

OfflineFirstWithGraphqlRepository streamlines the GraphQL integration with an OfflineFirstRepository. A serial queue is included to track GraphQL mutations in a separate SQLite database, only removing requests when a response is returned from the host (i.e. the device has lost internet connectivity).

The OfflineFirstWithGraphql domain uses all the same configurations and annotations as OfflineFirst.

To cache outbound requests, apply GraphqlOfflineQueueLink in your GraphqlProvider:

GraphqlProvider(
  link: Link.from([
    GraphqlOfflineQueueLink(
      GraphqlRequestSqliteCacheManager('myAppRequestQueue.sqlite'),
      // Optionally specify callbacks for queue retries and errors
      onReattempt: onReattempt,
      onRequestException: onRequestException,
    ),
    HttpLink(endpoint)
  ]),
);

⚠️ Be sure to place the queue above HttpLink or WebSocketLink or any other outbound Links.

Models #

ConnectOfflineFirstWithGraphql #

@ConnectOfflineFirstWithGraphql decorates the model that can be serialized by GraphQL and SQLite. Offline First does not have configuration at the class level and only extends configuration held by its providers:

@ConnectOfflineFirstWithGraphql(
  graphqlConfig: GraphqlSerializable(),
  sqliteConfig: SqliteSerializable(),
)
class MyModel extends OfflineFirstModel {}

FAQ #

Why can't I declare a model argument?

Due to an open analyzer bug, a custom model cannot be passed to the repository as a type argument.

Unsupported #

Field Types #

  • Any unsupported field types from GraphqlProvider or SqliteProvider
  • Future iterables of future models (i.e. Future<List<Future<Model>>>.

Configuration #

  • @OfflineFirst(where: only supports extremely simple renames. Multiple where keys (OfflineFirst(where: {'id': 'data["id"]', 'otherVar': 'data["otherVar"]'})) or nested properties (OfflineFirst(where: {'id': 'data["subfield"]["id"]})) will be ignored. Be sure to use @Graphql(name:) to rename the generated document field.
1
likes
140
points
211
downloads

Publisher

unverified uploader

Weekly Downloads

A Brick domain that routes data fetching through local providers before a GraphQL provider.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

brick_core, brick_graphql, brick_offline_first, brick_sqlite, gql, gql_exec, gql_link, logging, meta, sqflite_common

More

Packages that depend on brick_offline_first_with_graphql