addressRepository = $addressRepository; } /** * Get customer address for user * * @param int $addressId * @param int $userId * @return AddressInterface * @throws GraphQlAuthorizationException * @throws GraphQlNoSuchEntityException */ public function execute(int $addressId, int $userId): AddressInterface { try { /** @var AddressInterface $address */ $address = $this->addressRepository->getById($addressId); } catch (NoSuchEntityException $e) { throw new GraphQlNoSuchEntityException( __('Address id %1 does not exist.', [$addressId]) ); } if ($address->getCustomerId() != $userId) { throw new GraphQlAuthorizationException( __('Current customer does not have permission to address id %1', [$addressId]) ); } return $address; } }