query<T extends Model> method

  1. @override
Future<List<T>> query<T extends Model>(
  1. ModelType<T> modelType, {
  2. QueryPredicate<Model>? where,
  3. QueryPagination? pagination,
  4. List<QuerySortBy>? sortBy,
})
override

Implementation

@override
Future<List<T>> query<T extends Model>(ModelType<T> modelType,
    {QueryPredicate? where,
    QueryPagination? pagination,
    List<QuerySortBy>? sortBy}) async {
  try {
    await _setUpObserveIfNeeded();
    final List<Map<dynamic, dynamic>>? serializedResults =
        await (_channel.invokeListMethod('query', <String, dynamic>{
      'modelName': modelType.modelName(),
      'queryPredicate': where?.serializeAsMap(),
      'queryPagination': pagination?.serializeAsMap(),
      'querySort': sortBy?.map((element) => element.serializeAsMap()).toList()
    }));
    if (serializedResults == null)
      throw AmplifyException(
          AmplifyExceptionMessages.nullReturnedFromMethodChannel);
    return serializedResults
        .map((serializedResult) => modelType.fromJson(
            new Map<String, dynamic>.from(
                serializedResult["serializedData"])))
        .toList();
  } on PlatformException catch (e) {
    throw _deserializeException(e);
  } on TypeError catch (e) {
    throw DataStoreException(
        "An unrecognized exception has happened while Serialization/de-serialization." +
            " Please see underlyingException for more details.",
        recoverySuggestion:
            AmplifyExceptionMessages.missingRecoverySuggestion,
        underlyingException: e.toString());
  }
}