init
This commit is contained in:
19
schema/ApiTypes.php
Normal file
19
schema/ApiTypes.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace dominion\api\schema;
|
||||
|
||||
trait ApiTypes
|
||||
{
|
||||
private static $resultSave;
|
||||
private static $resultSaveError;
|
||||
|
||||
|
||||
public static function resultSave()
|
||||
{
|
||||
return self::$resultSave ?: (self::$resultSave = new ResultSaveType());
|
||||
}
|
||||
public static function resultSaveError()
|
||||
{
|
||||
return self::$resultSaveError ?: (self::$resultSaveError = new ResultSaveErrorType());
|
||||
}
|
||||
}
|
30
schema/ResultSaveErrorType.php
Normal file
30
schema/ResultSaveErrorType.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace dominion\api\schema;
|
||||
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
|
||||
class ResultSaveErrorType extends ObjectType
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$config = [
|
||||
'fields' => function() {
|
||||
return [
|
||||
'code' => [
|
||||
'type' => Type::string(),
|
||||
'description' => 'поле',
|
||||
],
|
||||
'messages' => [
|
||||
'type' => Type::listOf(Type::string()),
|
||||
'description' => 'текст ошибки',
|
||||
],
|
||||
];
|
||||
}
|
||||
];
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
}
|
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);
|
||||
}
|
||||
}
|
8
schema/Types.php
Normal file
8
schema/Types.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace dominion\api\schema;
|
||||
|
||||
class Types
|
||||
{
|
||||
use ApiTypes;
|
||||
}
|
Reference in New Issue
Block a user