init
This commit is contained in:
45
schema/ResultSaveType.php
Normal file
45
schema/ResultSaveType.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user