45 lines
1.4 KiB
PHP
45 lines
1.4 KiB
PHP
|
<?php
|
||
|
|
||
|
|
||
|
namespace dominion\api\schema;
|
||
|
|
||
|
use GraphQL\Type\Definition\ObjectType;
|
||
|
use GraphQL\Type\Definition\Type;
|
||
|
|
||
|
class ResultSaveType extends ObjectType
|
||
|
{
|
||
|
public function __construct()
|
||
|
{
|
||
|
$config = [
|
||
|
'fields' => function() {
|
||
|
return [
|
||
|
'id' => [
|
||
|
'type' => Type::int(),
|
||
|
'description' => 'Id',
|
||
|
],
|
||
|
'status' => [
|
||
|
'type' => Type::string(),
|
||
|
'description' => 'status',
|
||
|
'resolve' => function($root, $args) {
|
||
|
return empty($root->errors) ? 'success' : 'error';
|
||
|
}
|
||
|
],
|
||
|
'errors' => [
|
||
|
'type' => Type::listOf(Types::resultSaveError()),
|
||
|
'description' => 'ошибки',
|
||
|
'resolve' => function($root, $args) {
|
||
|
$output = [];
|
||
|
foreach ($root->errors as $key => $value)
|
||
|
{
|
||
|
$output[] = ['code' => $key, 'messages'=> $value];
|
||
|
}
|
||
|
return $output;
|
||
|
}
|
||
|
],
|
||
|
];
|
||
|
}
|
||
|
];
|
||
|
|
||
|
parent::__construct($config);
|
||
|
}
|
||
|
}
|