feat : graphql stores custom
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Wazaaa\GraphQL\Model\Resolver;
|
||||
|
||||
use Magento\Framework\GraphQl\Config\Element\Field;
|
||||
use Magento\Framework\GraphQl\Query\ResolverInterface;
|
||||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
|
||||
class Store implements ResolverInterface
|
||||
{
|
||||
|
||||
protected $_storeManager;
|
||||
|
||||
public function __construct(StoreManagerInterface $storeManager)
|
||||
{
|
||||
$this->_storeManager = $storeManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function resolve(
|
||||
Field $field,
|
||||
$context,
|
||||
ResolveInfo $info,
|
||||
array $value = null,
|
||||
array $args = null
|
||||
) {
|
||||
$storeManagerDataList = $this->_storeManager->getStores();
|
||||
$stores = [];
|
||||
foreach($storeManagerDataList as $store){
|
||||
$stores[] = ['label' => $store->getName(),'code' => $store->getCode(),'id' => $store->getId()];
|
||||
}
|
||||
|
||||
return [
|
||||
'total_count' => count($stores),
|
||||
'items' => $stores
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
|
||||
<module name="Wazaaa_GraphQL" setup_version="1.0.0">
|
||||
<sequence>
|
||||
<module name="Magento_GraphQL"/>
|
||||
</sequence>
|
||||
</module>
|
||||
</config>
|
||||
@@ -0,0 +1,12 @@
|
||||
type Query {
|
||||
getStores:getStoresOutput @resolver(class: "\\Wazaaa\\GraphQL\\Model\\Resolver\\Store") @doc(description: "")
|
||||
}
|
||||
type getStoresOutput {
|
||||
total_count: Int @doc(description: "")
|
||||
items: [getStore] @doc(description: "")
|
||||
}
|
||||
type getStore {
|
||||
label: String @doc(description: ""),
|
||||
code: String @doc(description: ""),
|
||||
id: String @doc(description: ""),
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
\Magento\Framework\Component\ComponentRegistrar::register(
|
||||
\Magento\Framework\Component\ComponentRegistrar::MODULE,
|
||||
'Wazaaa_GraphQL',
|
||||
__DIR__
|
||||
);
|
||||
Reference in New Issue
Block a user