mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-11 10:09:24 +03:00
Add ExecutionResult $extensions
https://facebook.github.io/graphql/#sec-Response-Format
This commit is contained in:
parent
4d024ee85e
commit
327cc52601
@ -14,15 +14,22 @@ class ExecutionResult
|
|||||||
* @var Error[]
|
* @var Error[]
|
||||||
*/
|
*/
|
||||||
public $errors;
|
public $errors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array[]
|
||||||
|
*/
|
||||||
|
public $extensions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @param array $errors
|
* @param array $errors
|
||||||
|
* @param array $extensions
|
||||||
*/
|
*/
|
||||||
public function __construct(array $data = null, array $errors = [])
|
public function __construct(array $data = null, array $errors = [], array $extensions = [])
|
||||||
{
|
{
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
$this->errors = $errors;
|
$this->errors = $errors;
|
||||||
|
$this->extensions = $extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,6 +42,10 @@ class ExecutionResult
|
|||||||
if (!empty($this->errors)) {
|
if (!empty($this->errors)) {
|
||||||
$result['errors'] = array_map(['GraphQL\Error', 'formatError'], $this->errors);
|
$result['errors'] = array_map(['GraphQL\Error', 'formatError'], $this->errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($this->extensions)) {
|
||||||
|
$result['extensions'] = (array) $this->extensions;
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
25
tests/Executor/ExecutionResultTest.php
Normal file
25
tests/Executor/ExecutionResultTest.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
namespace GraphQL\Tests\Executor;
|
||||||
|
|
||||||
|
use GraphQL\Executor\ExecutionResult;
|
||||||
|
|
||||||
|
class ExecutionResultTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testToArrayWithoutExtensions()
|
||||||
|
{
|
||||||
|
$executionResult = new ExecutionResult();
|
||||||
|
|
||||||
|
$this->assertEquals(['data' => null], $executionResult->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testToArrayExtensions()
|
||||||
|
{
|
||||||
|
$executionResult = new ExecutionResult(null, [], ['foo' => 'bar']);
|
||||||
|
|
||||||
|
$this->assertEquals(['data' => null, 'extensions' => ['foo' => 'bar']], $executionResult->toArray());
|
||||||
|
|
||||||
|
$executionResult->extensions = ['bar' => 'foo'];
|
||||||
|
|
||||||
|
$this->assertEquals(['data' => null, 'extensions' => ['bar' => 'foo']], $executionResult->toArray());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user