getCollectionByHandle method

Future<Collection> getCollectionByHandle(
  1. String collectionName, {
  2. bool deleteThisPartOfCache = false,
})

Returns a collection by handle.

Implementation

Future<Collection> getCollectionByHandle(String collectionName,
    {bool deleteThisPartOfCache = false}) async {
  try {
    final WatchQueryOptions _options = WatchQueryOptions(
        document: gql(getFeaturedCollectionQuery),
        variables: {'query': collectionName});
    final QueryResult result = await _graphQLClient!.query(_options);
    checkForError(result);
    if (deleteThisPartOfCache) {
      _graphQLClient!.cache.writeQuery(_options.asRequest, data: {});
    }
    return Collections.fromGraphJson(result.data!['collections'])
        .collectionList[0];
  } catch (e) {
    log(e.toString());
  }
  return Collection.fromGraphJson({});
}