query method
Future<KuzzleResponse>
query(
- KuzzleRequest request, {
- Map<
String, dynamic> ? volatile, - bool queueable = true,
Base method used to send read queries to Kuzzle
This is a low-level method, with offline queue management, exposed to allow advanced SDK users to bypass high-level methods.
Takes an optional Map [options]
with the following properties:
final options = {
'queueable': bool,
'volatile': Map<String, dynamic>,
};
Implementation
Future<KuzzleResponse> query(KuzzleRequest request,
{Map<String, dynamic>? volatile, bool queueable = true}) {
//final _request = KuzzleRequest.fromMap(request);
// bind volatile data
request.volatile ??= volatile ?? globalVolatile;
for (final item in globalVolatile!.keys) {
if (!request.volatile!.containsKey(item)) {
request.volatile![item] = globalVolatile![item];
}
}
request.volatile!['sdkInstanceId'] = protocol.id;
request.volatile!['sdkName'] = '2.0.0';
/*
* Do not add the token for the checkToken route,
* to avoid getting a token error when a developer
* simply wish to verify his token
*/
if ((jwt != null && jwt!.isNotEmpty) &&
!(request.controller == 'auth' && request.action == 'checkToken')) {
request.jwt = jwt;
}
if (queueFilter != null) {
// todo: implement queueFilter
}
// check queueing
if (_queuing) {
if (queueable) {
final completer = Completer<KuzzleResponse>();
final queuedRequest = _KuzzleQueuedRequest(
completer: completer,
request: request,
);
_cleanQueue();
_offlineQueue.add(queuedRequest);
emit(KuzzleEvents.OFFLINE_QUEUE_PUSH, [queuedRequest.request]);
return completer.future;
}
final error = KuzzleError('not_connected',
'Unable to execute request: not connected to a Kuzzle server.', 503);
emit(ProtocolEvents.QUERY_ERROR, [error, request]);
return Future.error(error);
}
_requests.add(request.requestId);
// todo: implement query options
return protocol.query(request).then(deprecationHandler.logDeprecation);
}