init
This commit is contained in:
34
schema/SettingsMutationType.php
Normal file
34
schema/SettingsMutationType.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace dominion\settings\schema;
|
||||
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
use dominion\settings\Settings;
|
||||
|
||||
class SettingsMutationType extends ObjectType
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$config = [
|
||||
'fields' => function() {
|
||||
return [
|
||||
'save' => [
|
||||
'type' => Type::int(),
|
||||
'description' => 'Сохранение наклейки',
|
||||
'args' => [
|
||||
'code' => Type::nonNull(Type::string()),
|
||||
'value' => Type::nonNull(Type::string()),
|
||||
],
|
||||
'resolve' => function($root, $args) {
|
||||
return Settings::setValue($args['code'], $args['value']);
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
];
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
}
|
48
schema/SettingsPaginationType.php
Normal file
48
schema/SettingsPaginationType.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace dominion\settings\schema;
|
||||
|
||||
use GraphQL\Type\Definition\Type;
|
||||
use dominion\api\GraphQLSchemaPagination;
|
||||
use dominion\settings\Settings;
|
||||
use dominion\api\GraphQLPagination;
|
||||
|
||||
|
||||
class SettingsPaginationType extends GraphQLSchemaPagination
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$config = [
|
||||
'fields' => function(){
|
||||
$output = $this->getCustomFields();
|
||||
$output['data'] = [
|
||||
'type' => Type::listOf(Types::settings()),
|
||||
'description' => 'Настройки',
|
||||
'args' => GraphQLPagination::argumentModify([
|
||||
'id' => [
|
||||
'type' => Type::int(),
|
||||
'description' => 'Id',
|
||||
],
|
||||
'code' => [
|
||||
'type' => Type::string(),
|
||||
'description' => 'символьный код',
|
||||
'modify' => true,
|
||||
'modifyOption' => ['in'],
|
||||
],
|
||||
'sort' => [
|
||||
'type' => Type::string(),
|
||||
'description' => 'Сортировка (пример "isNew_asc" или "isVisible_desc")',
|
||||
],
|
||||
]),
|
||||
'resolve' => function($root, $args){
|
||||
return Settings::getData($args, $root);
|
||||
}
|
||||
];
|
||||
return $output;
|
||||
}
|
||||
];
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
}
|
34
schema/SettingsType.php
Normal file
34
schema/SettingsType.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace dominion\settings\schema;
|
||||
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
|
||||
class SettingsType extends ObjectType
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$config = [
|
||||
'fields' => function() {
|
||||
return [
|
||||
'id' => [
|
||||
'type' => Type::int(),
|
||||
'description' => 'Id',
|
||||
],
|
||||
'code' => [
|
||||
'type' => Type::string(),
|
||||
'description' => 'code',
|
||||
],
|
||||
'value' => [
|
||||
'type' => Type::string(),
|
||||
'description' => 'value',
|
||||
],
|
||||
];
|
||||
}
|
||||
];
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
}
|
26
schema/Types.php
Normal file
26
schema/Types.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace dominion\settings\schema;
|
||||
|
||||
trait Types
|
||||
{
|
||||
private static $settings;
|
||||
private static $settingsPagination;
|
||||
//
|
||||
private static $settingsMutation;
|
||||
|
||||
public static function settings()
|
||||
{
|
||||
return self::$settings ?: (self::$settings = new SettingsType());
|
||||
}
|
||||
public static function settingsPagination()
|
||||
{
|
||||
return self::$settingsPagination ?: (self::$settingsPagination = new SettingsPaginationType());
|
||||
}
|
||||
|
||||
//
|
||||
public static function settingsMutation()
|
||||
{
|
||||
return self::$settingsMutation ?: (self::$settingsMutation = new SettingsMutationType());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user