getAllOrders method

Future<List<Order>?> getAllOrders(
  1. String customerAccessToken, {
  2. SortKeyOrder sortKey = SortKeyOrder.PROCESSED_AT,
  3. bool reverse = true,
  4. bool deleteThisPartOfCache = false,
})

Returns all Order in a List of Orders.

Returns a List of Orders from the Customer with the customerAccessToken.

Implementation

Future<List<Order>?> getAllOrders(String customerAccessToken,
    {SortKeyOrder sortKey = SortKeyOrder.PROCESSED_AT,
    bool reverse = true,
    bool deleteThisPartOfCache = false}) async {
  final QueryOptions _options =
      WatchQueryOptions(document: gql(getAllOrdersQuery), variables: {
    'accessToken': customerAccessToken,
    'sortKey': sortKey.parseToString(),
    'reverse': reverse
  });
  final QueryResult result =
      await ShopifyConfig.graphQLClient!.query(_options);
  checkForError(result);
  final orderResult =
      result.data!['customer']['orders'] as Map<String, dynamic>;
  Orders orders = Orders.fromGraphJson(orderResult);
  // Orders orders = Orders.fromJson(
  //     (((result.data ?? const {})['customer'] ?? const {})['orders'] ??
  //         const {}));
  if (deleteThisPartOfCache) {
    _graphQLClient!.cache.writeQuery(_options.asRequest, data: {});
  }
  return orders.orderList;
}