kuvalda-api/schema/ResultSaveType.php

45 lines
1.4 KiB
PHP
Raw Normal View History

2024-11-20 15:32:19 +03:00
<?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);
}
}