mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 12:56:05 +03:00
Merge pull request #37 from mcg-web/execution-result-extensions
Add ExecutionResult $extensions
This commit is contained in:
commit
7916c54926
@ -15,14 +15,21 @@ class ExecutionResult
|
||||
*/
|
||||
public $errors;
|
||||
|
||||
/**
|
||||
* @var array[]
|
||||
*/
|
||||
public $extensions;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @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->errors = $errors;
|
||||
$this->extensions = $extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,6 +43,10 @@ class ExecutionResult
|
||||
$result['errors'] = array_map(['GraphQL\Error', 'formatError'], $this->errors);
|
||||
}
|
||||
|
||||
if (!empty($this->extensions)) {
|
||||
$result['extensions'] = (array) $this->extensions;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,9 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
|
||||
public static function addImplementationToInterfaces(ObjectType $impl)
|
||||
{
|
||||
self::$_lazyLoadImplementations[] = function() use ($impl) {
|
||||
/** @var self $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 = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a implemented object type to interface
|
||||
*
|
||||
* @param ObjectType $impl
|
||||
*/
|
||||
protected function addImplementation(ObjectType $impl)
|
||||
{
|
||||
$this->_implementations[] = $impl;
|
||||
}
|
||||
|
||||
/**
|
||||
* InterfaceType constructor.
|
||||
* @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…
Reference in New Issue
Block a user