mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 04:46:04 +03:00
Fix CoroutineExecutor::resultToArray for associative arrays
This commit is contained in:
parent
31d89acfae
commit
2295b96a49
@ -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
|
||||
@ -152,9 +155,14 @@ class CoroutineExecutor implements Runtime, ExecutorImplementation
|
||||
|
||||
if (is_array($value)) {
|
||||
$array = [];
|
||||
foreach ($value as $item) {
|
||||
$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;
|
||||
}
|
||||
|
||||
|
@ -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'],
|
||||
];
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user