checkCustomerAccount = $checkCustomerAccount; $this->addressRepository = $addressRepository; $this->addressInterfaceFactory = $addressInterfaceFactory; $this->customerAddressDataProvider = $customerAddressDataProvider; $this->dataObjectHelper = $dataObjectHelper; $this->customerAddressCreateDataValidator = $customerAddressCreateDataValidator; } /** * @inheritdoc */ public function resolve( Field $field, $context, ResolveInfo $info, array $value = null, array $args = null ) { $currentUserId = $context->getUserId(); $currentUserType = $context->getUserType(); $this->checkCustomerAccount->execute($currentUserId, $currentUserType); $this->customerAddressCreateDataValidator->validate($args['input']); $address = $this->createCustomerAddress((int)$currentUserId, $args['input']); return $this->customerAddressDataProvider->getAddressData($address); } /** * Create customer address * * @param int $customerId * @param array $addressData * @return AddressInterface * @throws GraphQlInputException */ private function createCustomerAddress(int $customerId, array $addressData) : AddressInterface { /** @var AddressInterface $address */ $address = $this->addressInterfaceFactory->create(); $this->dataObjectHelper->populateWithArray($address, $addressData, AddressInterface::class); $address->setCustomerId($customerId); try { $address = $this->addressRepository->save($address); } catch (InputException $e) { throw new GraphQlInputException(__($e->getMessage()), $e); } return $address; } }