getCollectionByHandle method

  1. @Deprecated('Use [getCollectionById]')
Future<Collection> getCollectionByHandle(
  1. String collectionName, {
  2. List<MetafieldIdentifier>? metafields,
})

Returns a collection by handle.

Implementation

@Deprecated('Use [getCollectionById]')
Future<Collection> getCollectionByHandle(
  String collectionName, {
  List<MetafieldIdentifier>? metafields,
}) async {
  try {
    final WatchQueryOptions _options = WatchQueryOptions(
      document: gql(getFeaturedCollectionQuery),
      variables: {
        'query': collectionName,
        'country': ShopifyLocalization.countryCode,
        'metafields': metafields != null
            ? metafields.map((e) => e.toJson()).toList()
            : [],
      },
      fetchPolicy: ShopifyConfig.fetchPolicy,
    );
    final QueryResult result = await _graphQLClient!.query(_options);
    checkForError(result);
    return Collections.fromGraphJson(result.data!['collections'])
        .collectionList[0];
  } catch (e) {
    log(e.toString());
  }
  return Collection.fromGraphJson({});
}