getAllCollections method

Future<List<Collection>> getAllCollections({
  1. bool deleteThisPartOfCache = false,
  2. SortKeyCollection sortKeyCollection = SortKeyCollection.UPDATED_AT,
  3. bool reverse = false,
})

Returns all available collections.

Tip: When editing Collections you can choose on which channel or app you want to make them available.

Implementation

Future<List<Collection>> getAllCollections(
    {bool deleteThisPartOfCache = false,
    SortKeyCollection sortKeyCollection = SortKeyCollection.UPDATED_AT,
    bool reverse = false}) async {
  List<Collection> collectionList = [];
  Collections tempCollection;
  String? cursor;
  WatchQueryOptions _options;
  do {
    _options = WatchQueryOptions(
        document: gql(getAllCollectionsOptimizedQuery),
        variables: {
          'cursor': cursor,
          'sortKey': sortKeyCollection.parseToString(),
          'reverse': reverse
        });
    final QueryResult result = await _graphQLClient!.query(_options);
    checkForError(result);
    tempCollection = (Collections.fromGraphJson(
        (result.data ?? const {})['collections'] ?? {}));
    collectionList = tempCollection.collectionList + collectionList;
    cursor = collectionList.isNotEmpty ? collectionList.last.cursor : '';
  } while ((tempCollection.hasNextPage == true));
  if (deleteThisPartOfCache) {
    _graphQLClient!.cache.writeQuery(_options.asRequest, data: {});
  }
  return collectionList;
}