GraphQL\Executor\ExecutionResult::toArray PHP Метод

toArray() публичный Метод

public toArray ( ) : array
Результат 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

Пример #1
0
 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