Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit f35af8b

Browse files
author
Roman Glushko
committed
#31 Refactored the code
1 parent 85e6826 commit f35af8b

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

app/code/Magento/CmsGraphQl/Model/Resolver/Cms/CmsPageDataProvider.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
use Magento\Cms\Api\PageRepositoryInterface as CmsPageRepositoryInterface;
1212
use Magento\Framework\Exception\LocalizedException;
1313
use Magento\Framework\Exception\NoSuchEntityException;
14-
use Magento\Framework\Serialize\SerializerInterface;
15-
use Magento\Framework\Webapi\ServiceOutputProcessor;
1614

1715
/**
1816
* Cms field data provider, used for GraphQL request processing.
@@ -38,7 +36,7 @@ public function __construct(
3836
*
3937
* @param int $cmsPageId
4038
* @return array
41-
* @throws NoSuchEntityException|LocalizedException
39+
* @throws LocalizedException
4240
*/
4341
public function getCmsPageById(int $cmsPageId) : array
4442
{
@@ -78,4 +76,4 @@ private function processCmsPage(CmsPageInterface $cmsPageModel) : array
7876

7977
return $cmsPageData;
8078
}
81-
}
79+
}

app/code/Magento/CmsGraphQl/Model/Resolver/CmsPage.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
namespace Magento\CmsGraphQl\Model\Resolver;
99

1010
use Magento\CmsGraphQl\Model\Resolver\Cms\CmsPageDataProvider;
11-
use Magento\Framework\Exception\NoSuchEntityException;
1211
use Magento\Framework\GraphQl\Config\Element\Field;
1312
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
14-
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1513
use Magento\Framework\GraphQl\Query\Resolver\Value;
1614
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
1715
use Magento\Framework\GraphQl\Query\ResolverInterface;
@@ -56,18 +54,13 @@ public function resolve(
5654
) : Value {
5755

5856
$cmsPageId = $this->getCmsPageId($args);
57+
$cmsPageData = $this->cmsPageDataProvider->getCmsPageById($cmsPageId);
5958

60-
try {
61-
$cmsPageData = $this->cmsPageDataProvider->getCmsPageById($cmsPageId);
59+
$result = function () use ($cmsPageData) {
60+
return !empty($cmsPageData) ? $cmsPageData : [];
61+
};
6262

63-
$result = function () use ($cmsPageData) {
64-
return !empty($cmsPageData) ? $cmsPageData : [];
65-
};
66-
67-
return $this->valueFactory->create($result);
68-
} catch (NoSuchEntityException $exception) {
69-
throw new GraphQlNoSuchEntityException(__('CMS page with ID %1 does not exist.', [$cmsPageId]));
70-
}
63+
return $this->valueFactory->create($result);
7164
}
7265

7366
/**

0 commit comments

Comments
 (0)