customerUpdate method

Future<void> customerUpdate({
  1. String? email,
  2. String? firstName,
  3. String? lastName,
  4. String? password,
  5. String? phoneNumber,
  6. String? customerAccessToken,
  7. bool? acceptsMarketing,
})

Updates the customer to which customerAccessToken belongs to.

Implementation

Future<void> customerUpdate({
  String? email,
  String? firstName,
  String? lastName,
  String? password,
  String? phoneNumber,
  String? customerAccessToken,
  bool? acceptsMarketing,
}) async {
  Map<String, dynamic> variableMap = {};

  Map<String, dynamic> dataMap = {};
  dataMap['email'] = email;
  dataMap['firstName'] = firstName;
  dataMap['lastName'] = lastName;
  dataMap['acceptsMarketing'] = acceptsMarketing;
  dataMap['customerAccessToken'] = customerAccessToken;
  if (phoneNumber != null && phoneNumber.isNotEmpty) {
    dataMap['phone'] = phoneNumber;
  }
  if (password != null && password.isNotEmpty) {
    dataMap['password'] = password;
  }

  dataMap.forEach((k, v) => v != {} ? variableMap[k] = v : {});

  final MutationOptions _options = MutationOptions(
      document: gql(createValidMutationString(variableMap)),
      variables: variableMap);
  QueryResult result = await _graphQLClient!.mutate(_options);
  checkForError(
    result,
    key: 'customerUpdate',
    errorKey: 'customerUserErrors',
  );
}