Skip to content

Commit 7f1ce16

Browse files
committed
Improving pagination documentation
1 parent 91dd830 commit 7f1ce16

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/Mappers/Root/MyCLabsEnumTypeMapper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use phpDocumentor\Reflection\Type;
1515
use phpDocumentor\Reflection\Types\Object_;
1616
use ReflectionMethod;
17+
use TheCodingMachine\GraphQLite\Types\MyclabsEnumType;
1718
use function is_a;
1819
use function str_replace;
1920
use function strpos;
@@ -93,7 +94,7 @@ private function mapByClassName(string $enumClass): ?EnumType
9394
$constInstances[$key] = ['value' => $enumClass::$key()];
9495
}
9596

96-
return $this->cache[$enumClass] = new EnumType([
97+
return $this->cache[$enumClass] = new MyclabsEnumType([
9798
'name' => 'MyCLabsEnum_' . str_replace('\\', '__', $enumClass),
9899
'values' => $constInstances,
99100
]);

src/Types/MyclabsEnumType.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TheCodingMachine\GraphQLite\Types;
6+
7+
use GraphQL\Type\Definition\EnumType;
8+
use MyCLabs\Enum\Enum;
9+
use TheCodingMachine\GraphQLite\GraphQLRuntimeException;
10+
11+
/**
12+
* An extension of the EnumType to support Myclabs enum.
13+
*
14+
* This implementation is needed to overwrite the default "serialize" method, that expects to see the exact same object
15+
* (while there can be several instances of the same enum value with MyclabsEnum)
16+
*/
17+
class MyclabsEnumType extends EnumType
18+
{
19+
public function serialize($value)
20+
{
21+
if (! $value instanceof Enum) {
22+
throw new GraphQLRuntimeException('Expected a Myclab Enum instance');
23+
}
24+
return $value->getKey();
25+
}
26+
}

tests/Integration/EndToEndTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ public function testEndToEndEnums2(): void
953953
);
954954

955955
$this->assertSame([
956-
'echoProductType' => 'FOOD'
956+
'echoSomeProductType' => 'FOOD'
957957
], $result->toArray(Debug::RETHROW_INTERNAL_EXCEPTIONS)['data']);
958958
}
959959

0 commit comments

Comments
 (0)