removeLineItemsFromCheckout method

Future<Checkout> removeLineItemsFromCheckout({
  1. required String checkoutId,
  2. required List<LineItem> lineItems,
})

Returns the Checkout that checkoutId belongs to after removing the lineItems from it.

Implementation

Future<Checkout> removeLineItemsFromCheckout({
  required String checkoutId,
  required List<LineItem> lineItems,
}) async {
  final MutationOptions _options = MutationOptions(
      document: gql(removeLineItemsFromCheckoutMutation),
      variables: {
        'checkoutId': checkoutId,
        'lineItemIds': [for (var lineItem in lineItems) lineItem.id],
      });

  final QueryResult result = await _graphQLClient!.mutate(_options);
  checkForError(
    result,
    key: 'removeLineItemsFromCheckout',
    errorKey: 'checkoutUserErrors',
  );

  return Checkout.fromJson(
      ((result.data!['checkoutLineItemsRemove'] ?? const {})['checkout'] ??
          const {}));
}