Skip to content

Commit

Permalink
Fixed internal server error for query urlResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshsuhagiya committed Mar 6, 2019
1 parent 75cf826 commit ad4efb8
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Magento\UrlRewriteGraphQl\Model\Resolver;

use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
Expand Down Expand Up @@ -73,6 +74,11 @@ public function resolve(
$url = $customUrl ?: $url;
$urlRewrite = $this->findCanonicalUrl($url);
if ($urlRewrite) {
if (!$urlRewrite->getEntityId()) {
throw new GraphQlNoSuchEntityException(
__('No such entity found with matching URL key: %url', ['url' => $url])
);
}
$result = [
'id' => $urlRewrite->getEntityId(),
'canonical_url' => $urlRewrite->getTargetPath(),
Expand All @@ -99,6 +105,9 @@ private function findCanonicalUrl(string $requestPath) : ?\Magento\UrlRewrite\Se
if (!$urlRewrite) {
$urlRewrite = $this->findUrlFromTargetPath($requestPath);
}
if (!$urlRewrite->getEntityId() && !$urlRewrite->getIsAutogenerated()) {
$urlRewrite = $this->findUrlFromTargetPath($urlRewrite->getTargetPath());
}

return $urlRewrite;
}
Expand Down

0 comments on commit ad4efb8

Please sign in to comment.