I would like to create custom GraphQL for a custom module. but I am facing an issue. see below GraphQL response.
In the above image, you can see I am able to get the response of days
and **details**
value but unable to get the value of dates
it will return always null but actually value is present.
Below is my schema.graphql
type Query {
getInformation(id: String!): StoreHolidayInfo @resolver (class: "\\Namespace\\Modulename\\Model\\Resolver\\StoreHolidayInfo") @doc(description:"Returns holiday information about store")
}
type StoreHolidayInfo {
dates: [holidayDates]
days: String
details: [holidayDetails]
}
type holidayDates {
repetitive: Int
normal: Int
shipping_off_day: Int
}
type holidayDetails {
holiday_id: Int
holiday_name: String
holiday_applied_stores: String
holiday_date_from: String
holiday_date_to: String
holiday_comment: String
is_repetitive: Int
is_active: Int
all_store: Int
}
Below is my Resolver class.
<?php
declare(strict_types=1);
namespace Namespace\Modulename\Model\Resolver;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\Builder as SearchCriteriaBuilder;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Namespace\Modulename\Api\StoreInformationManagementInterface;
/**
* Class StoreHolidayInfo
* @package Namespace\Modulename\Model\Resolver
*/
class StoreHolidayInfo implements ResolverInterface
{
/**
* @var StoreInformationManagementInterface
*/
protected $storeInformationManagement;
/**
* StoreHolidayInfo constructor.
* @param StoreInformationManagementInterface $storeInformationManagement
*/
public function __construct(
StoreInformationManagementInterface $storeInformationManagement
) {
$this->storeInformationManagement = $storeInformationManagement;
}
/**
* @inheritdoc
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!isset($args['id']) || empty($args['id'])) {
throw new GraphQlInputException(__('"id" argument should be specified and not empty'));
}
$storeHoliday = $this->storeInformationManagement->getStoreHolidayInformation($args['storelocator_id']);
return [
'dates' => $storeHoliday[0]['dates'],
'days' => $storeHoliday[0]['days'],
'details' => $storeHoliday[0]['details']
];
}
}
If I print the $storeHoliday
object in Resolver file I am getting the below response.
Array
(
[0] => Array
(
[dates] => Array
(
[repetitive] => Array
(
[0] => 1-14
[1] => 1-15
[2] => 1-14
[3] => 1-15
[4] => 1-26
)
[normal] => Array
(
[0] => 01-14-2020
[1] => 01-15-2020
[2] => 01-26-2020
)
[shipping_off_day] => Array
(
)
)
[days] => 1
[details] => Array
(
[0] => Array
(
[holiday_id] => 1
[holiday_name] => Kites festival
[holiday_applied_stores] => 2,3,4
[holiday_date_from] => 2020-01-14
[holiday_date_to] => 2020-01-15
[holiday_comment] => <p>Kites festival</p>
[is_repetitive] => 1
[is_active] => 1
[all_store] => 1
)
[1] => Array
(
[holiday_id] => 2
[holiday_name] => Republic day
[holiday_applied_stores] => 2,3,4
[holiday_date_from] => 2020-01-26
[holiday_date_to] => 2020-01-26
[holiday_comment] => <p>Republic day</p>
[is_repetitive] => 1
[is_active] => 1
[all_store] => 0
)
)
)
)
So, in short, I am unable to get the value of dates
. what's going wrong in the above code. can anybody help me to solve this issue?
Any help would be appreciated! Thanks.