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

Commit

Permalink
#31 Refactored the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Glushko committed Jul 2, 2018
1 parent 85e6826 commit f35af8b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
use Magento\Cms\Api\PageRepositoryInterface as CmsPageRepositoryInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\Webapi\ServiceOutputProcessor;

/**
* Cms field data provider, used for GraphQL request processing.
Expand All @@ -38,7 +36,7 @@ public function __construct(
*
* @param int $cmsPageId
* @return array
* @throws NoSuchEntityException|LocalizedException
* @throws LocalizedException
*/
public function getCmsPageById(int $cmsPageId) : array
{
Expand Down Expand Up @@ -78,4 +76,4 @@ private function processCmsPage(CmsPageInterface $cmsPageModel) : array

return $cmsPageData;
}
}
}
17 changes: 5 additions & 12 deletions app/code/Magento/CmsGraphQl/Model/Resolver/CmsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
namespace Magento\CmsGraphQl\Model\Resolver;

use Magento\CmsGraphQl\Model\Resolver\Cms\CmsPageDataProvider;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
use Magento\Framework\GraphQl\Query\ResolverInterface;
Expand Down Expand Up @@ -56,18 +54,13 @@ public function resolve(
) : Value {

$cmsPageId = $this->getCmsPageId($args);
$cmsPageData = $this->cmsPageDataProvider->getCmsPageById($cmsPageId);

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

$result = function () use ($cmsPageData) {
return !empty($cmsPageData) ? $cmsPageData : [];
};

return $this->valueFactory->create($result);
} catch (NoSuchEntityException $exception) {
throw new GraphQlNoSuchEntityException(__('CMS page with ID %1 does not exist.', [$cmsPageId]));
}
return $this->valueFactory->create($result);
}

/**
Expand Down

0 comments on commit f35af8b

Please sign in to comment.