request method
A function called when a request reaches this Link
Implementation
@override
Stream<Response> request(Request request, [NextLink? forward]) async* {
final cacheItem = GraphqlRequestSqliteCache(request);
_logger.finest('GraphqlOfflineQueueLink#request: requesting ${cacheItem.toSqlite()}');
// Ignore "query" and "subscription" request
if (shouldCache(cacheItem.request)) {
final db = await requestManager.getDb();
// Log immediately before we make the request
await cacheItem.insertOrUpdate(db, logger: _logger);
}
yield* forward!(request).handleError(
(e) async {
_logger.warning('GraphqlOfflineQueueLink#request: error $e');
final db = await requestManager.getDb();
await cacheItem.unlock(db);
},
test: (e) {
return e is SocketException ||
(e is ServerException && e.originalException is SocketException);
},
).asyncMap((response) async {
if (response.errors?.isEmpty ?? true) {
final db = await requestManager.getDb();
// request was successfully sent and can be removed
_logger.finest('removing from queue: ${cacheItem.toSqlite()}');
await cacheItem.delete(db);
}
final db = await requestManager.getDb();
await cacheItem.unlock(db);
return response;
});
}