diff --git a/src/Executor/ExecutionResult.php b/src/Executor/ExecutionResult.php index 7fc7523..8f78ef3 100644 --- a/src/Executor/ExecutionResult.php +++ b/src/Executor/ExecutionResult.php @@ -37,7 +37,11 @@ class ExecutionResult */ public function toArray() { - $result = ['data' => $this->data]; + $result = []; + + if (null !== $this->data) { + $result['data'] = $this->data; + } if (!empty($this->errors)) { $result['errors'] = array_map(['GraphQL\Error', 'formatError'], $this->errors); diff --git a/tests/Executor/ExecutionResultTest.php b/tests/Executor/ExecutionResultTest.php index 1c942f7..68bff90 100644 --- a/tests/Executor/ExecutionResultTest.php +++ b/tests/Executor/ExecutionResultTest.php @@ -9,17 +9,17 @@ class ExecutionResultTest extends \PHPUnit_Framework_TestCase { $executionResult = new ExecutionResult(); - $this->assertEquals(['data' => null], $executionResult->toArray()); + $this->assertEquals([], $executionResult->toArray()); } public function testToArrayExtensions() { $executionResult = new ExecutionResult(null, [], ['foo' => 'bar']); - $this->assertEquals(['data' => null, 'extensions' => ['foo' => 'bar']], $executionResult->toArray()); + $this->assertEquals(['extensions' => ['foo' => 'bar']], $executionResult->toArray()); $executionResult->extensions = ['bar' => 'foo']; - $this->assertEquals(['data' => null, 'extensions' => ['bar' => 'foo']], $executionResult->toArray()); + $this->assertEquals(['extensions' => ['bar' => 'foo']], $executionResult->toArray()); } } diff --git a/tests/Executor/NonNullTest.php b/tests/Executor/NonNullTest.php index b2cd3cd..c0b67ef 100644 --- a/tests/Executor/NonNullTest.php +++ b/tests/Executor/NonNullTest.php @@ -243,7 +243,6 @@ class NonNullTest extends \PHPUnit_Framework_TestCase '; $expected = [ - 'data' => null, 'errors' => [ FormattedError::create($this->nonNullSyncError->getMessage(), [new SourceLocation(2, 17)]) ] @@ -259,7 +258,6 @@ class NonNullTest extends \PHPUnit_Framework_TestCase '; $expected = [ - 'data' => null, 'errors' => [ FormattedError::create('Cannot return null for non-nullable field DataType.nonNullSync.', [new SourceLocation(2, 17)]), ]