File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed
Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ You can find and compare releases at the [GitHub release page](https://github.co
99
1010## Unreleased
1111
12+ ### Added
13+
14+ - Provide a custom name for the Enum generated by ` PhpEnumType `
15+
1216## v15.2.5
1317
1418### Fixed
Original file line number Diff line number Diff line change @@ -17,8 +17,11 @@ class PhpEnumType extends EnumType
1717 /** @var class-string<\UnitEnum> */
1818 protected string $ enumClass ;
1919
20- /** @param class-string<\UnitEnum> $enum */
21- public function __construct (string $ enum )
20+ /**
21+ * @param class-string<\UnitEnum> $enum
22+ * @param string|null $name The name the enum will have in the schema, defaults to the basename of the given class
23+ */
24+ public function __construct (string $ enum , ?string $ name = null )
2225 {
2326 $ this ->enumClass = $ enum ;
2427 $ reflection = new \ReflectionEnum ($ enum );
@@ -36,7 +39,7 @@ public function __construct(string $enum)
3639 }
3740
3841 parent ::__construct ([
39- 'name ' => $ this ->baseName ($ enum ),
42+ 'name ' => $ name ?? $ this ->baseName ($ enum ),
4043 'values ' => $ enumDefinitions ,
4144 'description ' => $ this ->extractDescription ($ reflection ),
4245 ]);
Original file line number Diff line number Diff line change @@ -45,6 +45,23 @@ enum PhpEnum {
4545 );
4646 }
4747
48+ public function testConstructEnumTypeFromPhpEnumWithCustomName (): void
49+ {
50+ $ enumType = new PhpEnumType (PhpEnum::class, 'CustomNamedPhpEnum ' );
51+ self ::assertSame (
52+ <<<'GRAPHQL'
53+ "foo"
54+ enum CustomNamedPhpEnum {
55+ "bar"
56+ A
57+ B @deprecated
58+ C @deprecated(reason: "baz")
59+ }
60+ GRAPHQL,
61+ SchemaPrinter::printType ($ enumType )
62+ );
63+ }
64+
4865 public function testConstructEnumTypeFromPhpEnumWithDocBlockDescriptions (): void
4966 {
5067 $ enumType = new PhpEnumType (DocBlockPhpEnum::class);
You can’t perform that action at this time.
0 commit comments