addressRepository = $addressRepository; } /** * Get customer address. Throws exception if customer is not owner of address * * @param int $addressId * @param int $customerId * @return AddressInterface * @throws GraphQlAuthorizationException * @throws GraphQlNoSuchEntityException * @throws LocalizedException */ public function execute(int $addressId, int $customerId): AddressInterface { try { $customerAddress = $this->addressRepository->getById($addressId); } catch (NoSuchEntityException $e) { throw new GraphQlNoSuchEntityException( __('Could not find a address with ID "%address_id"', ['address_id' => $addressId]) ); } if ((int)$customerAddress->getCustomerId() !== $customerId) { throw new GraphQlAuthorizationException( __( 'The current user cannot use address with ID "%address_id"', ['address_id' => $addressId] ) ); } return $customerAddress; } }