Fix CoroutineExecutor::resultToArray for associative arrays

This commit is contained in:
Jan Bukva 2018-12-27 16:00:57 +01:00
parent 31d89acfae
commit 2295b96a49
No known key found for this signature in database
GPG Key ID: D5A7CEFD2A8F7D13
2 changed files with 16 additions and 12 deletions

View File

@ -34,8 +34,11 @@ use GraphQL\Utils\Utils;
use SplQueue;
use stdClass;
use Throwable;
use function array_keys;
use function count;
use function is_array;
use function is_string;
use function range;
use function sprintf;
class CoroutineExecutor implements Runtime, ExecutorImplementation
@ -151,9 +154,14 @@ class CoroutineExecutor implements Runtime, ExecutorImplementation
}
if (is_array($value)) {
$array = [];
foreach ($value as $item) {
$array[] = self::resultToArray($item);
$array = [];
$isAssoc = array_keys($value) !== range(0, count($value) - 1);
foreach ($value as $key => $item) {
if ($isAssoc) {
$array[$key] = self::resultToArray($item);
} else {
$array[] = self::resultToArray($item);
}
}
return $array;
}

View File

@ -23,9 +23,9 @@ class ExecutorSchemaTest extends TestCase
{
$BlogSerializableValueType = new CustomScalarType([
'name' => 'JsonSerializableValueScalar',
'serialize' => static function ($value) { return $value; },
'parseValue' => static function ($value) { return $value; },
'parseLiteral' => static function ($value) { return $value; },
'serialize' => static function ($value) {
return $value;
},
]);
$BlogArticle = null;
@ -201,9 +201,7 @@ class ExecutorSchemaTest extends TestCase
'keywords' => ['foo', 'bar', '1', 'true', null],
],
],
'meta' => [
'title' => 'My Article 1 | My Blog'
]
'meta' => [ 'title' => 'My Article 1 | My Blog' ],
],
],
];
@ -223,9 +221,7 @@ class ExecutorSchemaTest extends TestCase
'body' => 'This is a post',
'hidden' => 'This data is not exposed in the schema',
'keywords' => ['foo', 'bar', 1, true, null],
'meta' => [
'title' => 'My Article 1 | My Blog',
],
'meta' => ['title' => 'My Article 1 | My Blog'],
];
};