Skip to content

Commit f33db28

Browse files
authored
Merge pull request #1052 from sparklink-pro/enum_fix
Fix enum arguments transformer & tests
2 parents 53dd2b4 + 22a7cf8 commit f33db28

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/Definition/Type/PhpEnumType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public function __construct(array $config)
7575
}
7676
}
7777

78+
public function isEnumPhp(): bool
79+
{
80+
return null !== $this->enumClass;
81+
}
82+
7883
public function parseValue($value): mixed
7984
{
8085
if ($this->enumClass) {

src/Transformer/ArgumentsTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private function populateObject(Type $type, $data, bool $multiple, ResolveInfo $
8282

8383
if ($type instanceof EnumType) {
8484
/** Enum based on PHP Enum are already processed by PhpEnumType */
85-
if (isset($type->config['enumClass'])) { /** @phpstan-ignore-line */
85+
if ($type instanceof PhpEnumType && $type->isEnumPhp()) { /** @phpstan-ignore-line */
8686
return $data;
8787
}
8888
$instance = $this->getTypeClassInstance($type->name);

tests/Transformer/ArgumentsTransformerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
use Exception;
88
use Generator;
9-
use GraphQL\Type\Definition\EnumType;
109
use GraphQL\Type\Definition\InputObjectType;
1110
use GraphQL\Type\Definition\ListOfType;
1211
use GraphQL\Type\Definition\NonNull;
1312
use GraphQL\Type\Definition\ResolveInfo;
1413
use GraphQL\Type\Definition\Type;
1514
use GraphQL\Type\Schema;
15+
use Overblog\GraphQLBundle\Definition\Type\PhpEnumType;
1616
use Overblog\GraphQLBundle\Error\InvalidArgumentError;
1717
use Overblog\GraphQLBundle\Error\InvalidArgumentsError;
1818
use Overblog\GraphQLBundle\Transformer\ArgumentsTransformer;
@@ -64,7 +64,7 @@ public static function getTypes(): array
6464
],
6565
]);
6666

67-
$t3 = new EnumType([
67+
$t3 = new PhpEnumType([
6868
'name' => 'Enum1',
6969
'values' => ['op1' => 1, 'op2' => 2, 'op3' => 3],
7070
]);
@@ -88,7 +88,7 @@ public static function getTypes(): array
8888
$types = [$t1, $t2, $t3, $t4];
8989

9090
if (PHP_VERSION_ID >= 80100) {
91-
$t5 = new EnumType([
91+
$t5 = new PhpEnumType([
9292
'name' => 'EnumPhp',
9393
'enumClass' => EnumPhp::class,
9494
'values' => [

0 commit comments

Comments
 (0)