public function testNullsOutErrorSubtrees()
{
$doc = '{
sync
syncError
syncRawError
syncReturnError
syncReturnErrorList
async
asyncReject
asyncRawReject
asyncEmptyReject
asyncError
asyncRawError
asyncReturnError
}';
$data = ['sync' => function () {
return 'sync';
}, 'syncError' => function () {
throw new \Exception('Error getting syncError');
}, 'syncRawError' => function () {
throw new \Exception('Error getting syncRawError');
}, 'syncReturnError' => function () {
return new \Exception('Error getting syncReturnError');
}, 'syncReturnErrorList' => function () {
return ['sync0', new \Exception('Error getting syncReturnErrorList1'), 'sync2', new \Exception('Error getting syncReturnErrorList3')];
}, 'async' => function () {
return new Promise(function (callable $resolve) {
return $resolve('async');
});
}, 'asyncReject' => function () {
return new Promise(function ($_, callable $reject) {
return $reject('Error getting asyncReject');
});
}, 'asyncRawReject' => function () {
return \React\Promise\reject('Error getting asyncRawReject');
}, 'asyncEmptyReject' => function () {
return \React\Promise\reject();
}, 'asyncError' => function () {
return new Promise(function () {
throw new \Exception('Error getting asyncError');
});
}, 'asyncRawError' => function () {
return new Promise(function () {
throw new \Exception('Error getting asyncRawError');
});
}, 'asyncReturnError' => function () {
return \React\Promise\resolve(new \Exception('Error getting asyncReturnError'));
}];
$docAst = Parser::parse($doc);
$schema = new Schema(['query' => new ObjectType(['name' => 'Type', 'fields' => ['sync' => ['type' => Type::string()], 'syncError' => ['type' => Type::string()], 'syncRawError' => ['type' => Type::string()], 'syncReturnError' => ['type' => Type::string()], 'syncReturnErrorList' => ['type' => Type::listOf(Type::string())], 'async' => ['type' => Type::string()], 'asyncReject' => ['type' => Type::string()], 'asyncRawReject' => ['type' => Type::string()], 'asyncEmptyReject' => ['type' => Type::string()], 'asyncError' => ['type' => Type::string()], 'asyncRawError' => ['type' => Type::string()], 'asyncReturnError' => ['type' => Type::string()]]])]);
$expected = ['data' => ['sync' => 'sync', 'syncError' => null, 'syncRawError' => null, 'syncReturnError' => null, 'syncReturnErrorList' => ['sync0', null, 'sync2', null], 'async' => 'async', 'asyncReject' => null, 'asyncRawReject' => null, 'asyncEmptyReject' => null, 'asyncError' => null, 'asyncRawError' => null, 'asyncReturnError' => null], 'errors' => [['message' => 'Error getting syncError', 'locations' => [['line' => 3, 'column' => 7]], 'path' => ['syncError']], ['message' => 'Error getting syncRawError', 'locations' => [['line' => 4, 'column' => 7]], 'path' => ['syncRawError']], ['message' => 'Error getting syncReturnError', 'locations' => [['line' => 5, 'column' => 7]], 'path' => ['syncReturnError']], ['message' => 'Error getting syncReturnErrorList1', 'locations' => [['line' => 6, 'column' => 7]], 'path' => ['syncReturnErrorList', 1]], ['message' => 'Error getting syncReturnErrorList3', 'locations' => [['line' => 6, 'column' => 7]], 'path' => ['syncReturnErrorList', 3]], ['message' => 'Error getting asyncReject', 'locations' => [['line' => 8, 'column' => 7]], 'path' => ['asyncReject']], ['message' => 'Error getting asyncRawReject', 'locations' => [['line' => 9, 'column' => 7]], 'path' => ['asyncRawReject']], ['message' => 'An unknown error occurred.', 'locations' => [['line' => 10, 'column' => 7]], 'path' => ['asyncEmptyReject']], ['message' => 'Error getting asyncError', 'locations' => [['line' => 11, 'column' => 7]], 'path' => ['asyncError']], ['message' => 'Error getting asyncRawError', 'locations' => [['line' => 12, 'column' => 7]], 'path' => ['asyncRawError']], ['message' => 'Error getting asyncReturnError', 'locations' => [['line' => 13, 'column' => 7]], 'path' => ['asyncReturnError']]]];
Executor::setPromiseAdapter(new ReactPromiseAdapter());
$result = Executor::execute($schema, $docAst, $data);
$this->assertEquals($expected, self::awaitPromise($result));
}