Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Executor/ExecutionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@ class ExecutionResult
* @var Error[]
*/
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;
}

/**
Expand All @@ -35,6 +42,10 @@ public function toArray()
if (!empty($this->errors)) {
$result['errors'] = array_map(['GraphQL\Error', 'formatError'], $this->errors);
}

if (!empty($this->extensions)) {
$result['extensions'] = (array) $this->extensions;
}

return $result;
}
Expand Down
13 changes: 12 additions & 1 deletion src/Type/Definition/InterfaceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
}
Expand All @@ -66,6 +67,16 @@ public static function loadImplementationToInterfaces()
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
Expand Down
25 changes: 25 additions & 0 deletions tests/Executor/ExecutionResultTest.php
Original file line number Diff line number Diff line change
@@ -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());
}
}