mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-16 20:33:14 +03:00
Merge pull request #37 from mcg-web/execution-result-extensions
Add ExecutionResult $extensions
This commit is contained in:
commit
7916c54926
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,9 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
|
|||||||
public static function addImplementationToInterfaces(ObjectType $impl)
|
public static function addImplementationToInterfaces(ObjectType $impl)
|
||||||
{
|
{
|
||||||
self::$_lazyLoadImplementations[] = function() use ($impl) {
|
self::$_lazyLoadImplementations[] = function() use ($impl) {
|
||||||
|
/** @var self $interface */
|
||||||
foreach ($impl->getInterfaces() as $interface) {
|
foreach ($impl->getInterfaces() as $interface) {
|
||||||
$interface->_implementations[] = $impl;
|
$interface->addImplementation($impl);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -66,6 +67,16 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
|
|||||||
self::$_lazyLoadImplementations = [];
|
self::$_lazyLoadImplementations = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a implemented object type to interface
|
||||||
|
*
|
||||||
|
* @param ObjectType $impl
|
||||||
|
*/
|
||||||
|
protected function addImplementation(ObjectType $impl)
|
||||||
|
{
|
||||||
|
$this->_implementations[] = $impl;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* InterfaceType constructor.
|
* InterfaceType constructor.
|
||||||
* @param array $config
|
* @param array $config
|
||||||
|
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