2015-08-17 20:01:55 +06:00
|
|
|
<?php
|
|
|
|
namespace GraphQL\Executor;
|
|
|
|
|
|
|
|
use GraphQL\Error;
|
|
|
|
|
|
|
|
class ExecutionResult
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $data;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Error[]
|
|
|
|
*/
|
|
|
|
public $errors;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
* @param array $errors
|
|
|
|
*/
|
|
|
|
public function __construct(array $data = null, array $errors = [])
|
|
|
|
{
|
|
|
|
$this->data = $data;
|
|
|
|
$this->errors = $errors;
|
|
|
|
}
|
|
|
|
|
2015-11-02 20:39:51 +06:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-08-17 20:01:55 +06:00
|
|
|
public function toArray()
|
|
|
|
{
|
|
|
|
$result = ['data' => $this->data];
|
|
|
|
|
|
|
|
if (!empty($this->errors)) {
|
|
|
|
$result['errors'] = array_map(['GraphQL\Error', 'formatError'], $this->errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|