Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Fixed internal server error for query urlResolver #445

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()) {
yogeshsuhagiya marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We hide errors here.

Simple example:

  1. Create Custom URL Rewrite
    Request Path: go-to-admin
    Target Path: /admin
    Redirect Type: No
  2. Perform query:
query{
  urlResolver(
    url: "go-to-admin"
  ) {
    id
    relative_url
    type
  }
}

For this case expected response in Internal Server Error which means

Exception #0 (LogicException): Front controller reached 100 router match iterations

but we simply got "No such entity found with matching URL key: go-to-admin"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to rely on Magento error handling then just check if our response is casting to true or false? @naydav?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exception #0 (LogicException): Front controller reached 100 router match iterations
Looks like it's bug in Magento. expected result: 404 Page not found

Does everything else work?

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