getAllOrders method
Future<List<Order> >
getAllOrders(
- String customerAccessToken, {
- SortKeyOrder sortKey = SortKeyOrder.PROCESSED_AT,
- bool reverse = true,
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,
}) async {
// getAllOrdersQuery is a read-only `query`; sending it through mutate()
// bypassed the cache entirely and ignored ShopifyConfig.fetchPolicy.
final WatchQueryOptions _options = WatchQueryOptions(
document: gql(getAllOrdersQuery),
variables: {
'accessToken': customerAccessToken,
'sortKey': sortKey.parseToString(),
'reverse': reverse,
'country': ShopifyLocalization.countryCode,
},
fetchPolicy: ShopifyConfig.fetchPolicy,
);
QueryResult result = await _graphQLClient!.query(_options);
checkForError(result);
final ordersData = result.data!['customer']?['orders'];
if (ordersData == null) return [];
final orderResult = ordersData as Map<String, dynamic>;
Orders orders = Orders.fromGraphJson(orderResult);
// Orders orders = Orders.fromJson(
// (((result.data ?? const {})['customer'] ?? const {})['orders'] ??
// const {}));
return orders.orderList;
}