getProductList method

Future getProductList(
  1. String categoryLink,
  2. int page,
  3. int limit,
  4. List filter,
)

Implementation

Future getProductList(
    String categoryLink, int page, int limit, List filter) async {
  GraphQLClient _client = graphQLConfiguration.clientToQuery();

  var productListGql = """
                  query getProductList(
                  \$categoryLink: String
                  \$page: Int
                  \$limit: Int
                  \$filter: [FilterAttribute]
                ) {
                  getProductList(
                    categoryLink: \$categoryLink
                    page: \$page
                    limit: \$limit
                    filter: \$filter
                  ) {
                    product {
                      _id
                      productId
                      name
                      description
                      imageId
                      type
                      moq
                      isOutofstock
                      isMultiple
                      price {
                        sellingPrice
                        mrp
                        discount
                        minPrice
                        maxPrice
                        type
                        isSamePrice
                        __typename
                      }
                      images {
                        imageName
                        position
                        __typename
                      }
                      __typename
                    }
                    currentPage
                    totalPages
                    count
                    __typename
                  }
                }

          """;

  final vble = {
    "categoryLink": categoryLink,
    "page": page,
    "limit": limit,
    "filter": filter
  };
  QueryResult result = await _client.query(QueryOptions(
    document: gql(productListGql),
    variables: vble,
    fetchPolicy: FetchPolicy.networkOnly,
  ));

  if (!result.hasException) {
    var categoryPack = result.data!['getProductList'];

    if (categoryPack != null && categoryPack.length > 0) {
      categoryPackWithSet = productListFromJson(categoryPack);
    }
    return categoryPackWithSet;
  }
  return categoryPackWithSet;
}