mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 12:56:05 +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 SplQueue;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
use function array_keys;
|
||||||
|
use function count;
|
||||||
use function is_array;
|
use function is_array;
|
||||||
use function is_string;
|
use function is_string;
|
||||||
|
use function range;
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
|
||||||
class CoroutineExecutor implements Runtime, ExecutorImplementation
|
class CoroutineExecutor implements Runtime, ExecutorImplementation
|
||||||
@ -152,9 +155,14 @@ class CoroutineExecutor implements Runtime, ExecutorImplementation
|
|||||||
|
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
$array = [];
|
$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);
|
$array[] = self::resultToArray($item);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,9 +23,9 @@ class ExecutorSchemaTest extends TestCase
|
|||||||
{
|
{
|
||||||
$BlogSerializableValueType = new CustomScalarType([
|
$BlogSerializableValueType = new CustomScalarType([
|
||||||
'name' => 'JsonSerializableValueScalar',
|
'name' => 'JsonSerializableValueScalar',
|
||||||
'serialize' => static function ($value) { return $value; },
|
'serialize' => static function ($value) {
|
||||||
'parseValue' => static function ($value) { return $value; },
|
return $value;
|
||||||
'parseLiteral' => static function ($value) { return $value; },
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$BlogArticle = null;
|
$BlogArticle = null;
|
||||||
@ -201,9 +201,7 @@ class ExecutorSchemaTest extends TestCase
|
|||||||
'keywords' => ['foo', 'bar', '1', 'true', null],
|
'keywords' => ['foo', 'bar', '1', 'true', null],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'meta' => [
|
'meta' => [ 'title' => 'My Article 1 | My Blog' ],
|
||||||
'title' => 'My Article 1 | My Blog'
|
|
||||||
]
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@ -223,9 +221,7 @@ class ExecutorSchemaTest extends TestCase
|
|||||||
'body' => 'This is a post',
|
'body' => 'This is a post',
|
||||||
'hidden' => 'This data is not exposed in the schema',
|
'hidden' => 'This data is not exposed in the schema',
|
||||||
'keywords' => ['foo', 'bar', 1, true, null],
|
'keywords' => ['foo', 'bar', 1, true, null],
|
||||||
'meta' => [
|
'meta' => ['title' => 'My Article 1 | My Blog'],
|
||||||
'title' => 'My Article 1 | My Blog',
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user