getCollectionById method

Future<Collection?> getCollectionById(
  1. String collectionId
)

Returns a collection by id.

Implementation

Future<Collection?> getCollectionById(String collectionId) async {
  try {
    final WatchQueryOptions _options = WatchQueryOptions(
      document: gql(getCollectionsByIdsQuery),
      variables: {
        'ids': [collectionId],
      },
      fetchPolicy: ShopifyConfig.fetchPolicy,
    );
    final QueryResult result = await _graphQLClient!.query(_options);
    checkForError(result);
    return Collection.fromGraphJson(result.data!);
  } catch (e) {
    log(e.toString());
  }
  return null;
}