Skip to content

Commit 8a97d7a

Browse files
authored
Merge pull request #2 from landofcoder/update-graphql
Update graphql
2 parents e9e0073 + 500860e commit 8a97d7a

24 files changed

+1535
-74
lines changed

Model/Resolver/Categories.php

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
21+
22+
declare(strict_types=1);
23+
24+
namespace Lof\FaqGraphQl\Model\Resolver;
25+
26+
use Lof\Faq\Api\CategoriesInterface;
27+
use Magento\Framework\GraphQl\Config\Element\Field;
28+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
29+
use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\Builder as SearchCriteriaBuilder;
30+
use Magento\Framework\GraphQl\Query\ResolverInterface;
31+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
32+
33+
class Categories implements ResolverInterface
34+
{
35+
/**
36+
* @var SearchCriteriaBuilder
37+
*/
38+
private $searchCriteriaBuilder;
39+
/**
40+
* @var CategoriesInterface
41+
*/
42+
private $categoryInterface;
43+
44+
/**
45+
* Categories constructor.
46+
* @param CategoriesInterface $categories
47+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
48+
*/
49+
public function __construct(
50+
CategoriesInterface $categories,
51+
SearchCriteriaBuilder $searchCriteriaBuilder
52+
) {
53+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
54+
$this->categoryInterface = $categories;
55+
}
56+
57+
/**
58+
* @inheritdoc
59+
*/
60+
public function resolve(
61+
Field $field,
62+
$context,
63+
ResolveInfo $info,
64+
array $value = null,
65+
array $args = null
66+
) {
67+
if ($args['currentPage'] < 1) {
68+
throw new GraphQlInputException(__('currentPage value must be greater than 0.'));
69+
}
70+
if ($args['pageSize'] < 1) {
71+
throw new GraphQlInputException(__('pageSize value must be greater than 0.'));
72+
}
73+
$searchCriteria = $this->searchCriteriaBuilder->build('faqCategories', $args);
74+
$searchCriteria->setCurrentPage($args['currentPage']);
75+
$searchCriteria->setPageSize($args['pageSize']);
76+
$search = '';
77+
if (isset($args['search']) && $args['search']) {
78+
$search = $args['search'];
79+
}
80+
$searchResult = $this->categoryInterface->getList($searchCriteria, $search);
81+
$totalPages = $args['pageSize'] ? ((int)ceil($searchResult->getTotalCount() / $args['pageSize'])) : 0;
82+
83+
return [
84+
'total_count' => $searchResult->getTotalCount(),
85+
'items' => $searchResult->getItems(),
86+
'page_info' => [
87+
'page_size' => $args['pageSize'],
88+
'current_page' => $args['currentPage'],
89+
'total_pages' => $totalPages
90+
],
91+
];
92+
}
93+
}
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
21+
22+
namespace Lof\FaqGraphQl\Model\Resolver;
23+
24+
use Lof\Faq\Api\QuestionListByCategoryInterface;
25+
use Magento\Framework\Exception\LocalizedException;
26+
use Magento\Framework\GraphQl\Config\Element\Field;
27+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
28+
use Magento\Framework\GraphQl\Query\Resolver\Value;
29+
use Magento\Framework\GraphQl\Query\ResolverInterface;
30+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
31+
use Magento\Store\Model\StoreManagerInterface;
32+
33+
/**
34+
* Class to resolve custom attribute_set_name field in faq category GraphQL query
35+
*/
36+
class CategoryImageResolver implements ResolverInterface
37+
{
38+
39+
/**
40+
* @var QuestionListByCategoryInterface
41+
*/
42+
private $questionListByCategory;
43+
/**
44+
* @var StoreManagerInterface
45+
*/
46+
private $_storeManager;
47+
48+
/**
49+
* CategoryQuestionResolver constructor.
50+
* @param QuestionListByCategoryInterface $questionListByCategory
51+
* @param StoreManagerInterface $storeManager
52+
*/
53+
public function __construct(
54+
QuestionListByCategoryInterface $questionListByCategory,
55+
StoreManagerInterface $storeManager
56+
) {
57+
$this->questionListByCategory = $questionListByCategory;
58+
$this->_storeManager = $storeManager;
59+
}
60+
61+
/**
62+
* @param Field $field
63+
* @param ContextInterface $context
64+
* @param ResolveInfo $info
65+
* @param array|null $value
66+
* @param array|null $args
67+
* @return array|Value|mixed
68+
* @throws LocalizedException
69+
*/
70+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
71+
{
72+
if (isset($value['image']) && $value['image']) {
73+
return $this->_storeManager->getStore()->getBaseUrl(
74+
\Magento\Framework\UrlInterface::URL_TYPE_MEDIA
75+
) . $value['image'];
76+
} else {
77+
return '';
78+
}
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
21+
22+
namespace Lof\FaqGraphQl\Model\Resolver;
23+
24+
use Lof\Faq\Api\QuestionListByCategoryInterface;
25+
use Magento\Framework\GraphQl\Config\Element\Field;
26+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
27+
use Magento\Framework\GraphQl\Query\Resolver\Value;
28+
use Magento\Framework\GraphQl\Query\ResolverInterface;
29+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
30+
31+
/**
32+
* Class to resolve custom attribute_set_name field in faq category GraphQL query
33+
*/
34+
class CategoryQuestionResolver implements ResolverInterface
35+
{
36+
37+
/**
38+
* @var QuestionListByCategoryInterface
39+
*/
40+
private $questionListByCategory;
41+
42+
/**
43+
* CategoryQuestionResolver constructor.
44+
* @param QuestionListByCategoryInterface $questionListByCategory
45+
*/
46+
public function __construct(
47+
QuestionListByCategoryInterface $questionListByCategory
48+
) {
49+
$this->questionListByCategory = $questionListByCategory;
50+
}
51+
52+
/**
53+
* @param Field $field
54+
* @param ContextInterface $context
55+
* @param ResolveInfo $info
56+
* @param array|null $value
57+
* @param array|null $args
58+
* @return array|Value|mixed
59+
* @throws \Magento\Framework\Exception\LocalizedException
60+
*/
61+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
62+
{
63+
if (isset($value['category_id']) && $value['category_id']) {
64+
$result = $this->questionListByCategory->getQuestionByCategoryForApi($value['category_id']);
65+
return [
66+
'total_count' => $result->getTotalCount(),
67+
'items' => $result->getItems()
68+
];
69+
} else {
70+
return [];
71+
}
72+
}
73+
}

Model/Resolver/DataProvider/FaqCategory.php

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
<?php
2-
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
321

422
namespace Lof\FaqGraphQl\Model\Resolver\DataProvider;
523

624
use Lof\Faq\Api\CategoriesInterface;
725

8-
/**
9-
* Class FaqCategory
10-
* @package Lof\FaqGraphQl\Model\Resolver\DataProvider
11-
*/
1226
class FaqCategory
1327
{
1428

Model/Resolver/DataProvider/FaqQuestion.php

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
<?php
2-
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
321

422
namespace Lof\FaqGraphQl\Model\Resolver\DataProvider;
523

624
use Lof\Faq\Api\QuestionManagementInterface;
725

8-
/**
9-
* Class FaqQuestion
10-
* @package Lof\FaqGraphQl\Model\Resolver\DataProvider
11-
*/
1226
class FaqQuestion
1327
{
1428

Model/Resolver/DataProvider/FaqTag.php

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
<?php
2-
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
321

422
namespace Lof\FaqGraphQl\Model\Resolver\DataProvider;
523

@@ -8,6 +26,9 @@
826
class FaqTag
927
{
1028

29+
/**
30+
* @var TagsInterface
31+
*/
1132
private $tagsManagement;
1233

1334
/**
@@ -19,6 +40,9 @@ public function __construct(
1940
$this->tagsManagement = $tagsManagement;
2041
}
2142

43+
/**
44+
* @return string
45+
*/
2246
public function getFaqTag()
2347
{
2448
return 'proviced data';

Model/Resolver/FaqCategory.php

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
<?php
2-
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
321

422
namespace Lof\FaqGraphQl\Model\Resolver;
523

6-
use Magento\Framework\Exception\NoSuchEntityException;
724
use Magento\Framework\GraphQl\Config\Element\Field;
8-
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
9-
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1025
use Magento\Framework\GraphQl\Query\ResolverInterface;
1126
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1227

0 commit comments

Comments
 (0)