getCollectionsByIds method

Future<List<Collection>?> getCollectionsByIds(
  1. List<String> idList, {
  2. bool deleteThisPartOfCache = false,
})

Returns a List of Collection

Implementation

Future<List<Collection>?> getCollectionsByIds(List<String> idList,
    {bool deleteThisPartOfCache = false}) async {
  try {
    final WatchQueryOptions _options = WatchQueryOptions(
        document: gql(getCollectionsByIdsQuery), variables: {'ids': idList});
    final QueryResult result = await _graphQLClient!.query(_options);
    checkForError(result);
    if (deleteThisPartOfCache) {
      _graphQLClient!.cache.writeQuery(_options.asRequest, data: {});
    }

    var newResponse = List.generate(result.data!['nodes']?.length ?? 0,
        (index) => {"node": (result.data!['nodes'] ?? const {})[index]});
    var tempCollection = {"edges": newResponse};
    return Collections.fromGraphJson(tempCollection).collectionList;
  } catch (e) {
    log(e.toString());
  }
  return [Collection.fromJson({})];
}