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