GraphQL\Executor\ExecutionResult::toArray PHP Method

toArray() public method

public toArray ( ) : array
return array
    public function toArray()
    {
        $result = [];
        if (null !== $this->data) {
            $result['data'] = $this->data;
        }
        if (!empty($this->errors)) {
            $result['errors'] = array_map(['GraphQL\\Error\\Error', 'formatError'], $this->errors);
        }
        if (!empty($this->extensions)) {
            $result['extensions'] = (array) $this->extensions;
        }
        return $result;
    }

Usage Example

 public function testToArrayExtensions()
 {
     $executionResult = new ExecutionResult(null, [], ['foo' => 'bar']);
     $this->assertEquals(['extensions' => ['foo' => 'bar']], $executionResult->toArray());
     $executionResult->extensions = ['bar' => 'foo'];
     $this->assertEquals(['extensions' => ['bar' => 'foo']], $executionResult->toArray());
 }
ExecutionResult