33namespace GraphQL \Type \Definition ;
44
55use GraphQL \Error \SerializationError ;
6+ use GraphQL \Language \AST \EnumTypeDefinitionNode ;
7+ use GraphQL \Language \AST \EnumTypeExtensionNode ;
68use GraphQL \Utils \PhpDoc ;
79use GraphQL \Utils \Utils ;
810
@@ -16,16 +18,23 @@ class PhpEnumType extends EnumType
1618 protected string $ enumClass ;
1719
1820 /**
19- * @param class-string<\UnitEnum> $enum
21+ * @param class-string<\UnitEnum> $enumClass The fully qualified class name of a native PHP enum
2022 * @param string|null $name The name the enum will have in the schema, defaults to the basename of the given class
23+ * @param string|null $description The description the enum will have in the schema, defaults to PHPDoc of the given class
24+ * @param array<EnumTypeExtensionNode>|null $extensionASTNodes
2125 *
2226 * @throws \Exception
2327 * @throws \ReflectionException
2428 */
25- public function __construct (string $ enum , ?string $ name = null )
26- {
27- $ this ->enumClass = $ enum ;
28- $ reflection = new \ReflectionEnum ($ enum );
29+ public function __construct (
30+ string $ enumClass ,
31+ ?string $ name = null ,
32+ ?string $ description = null ,
33+ ?EnumTypeDefinitionNode $ astNode = null ,
34+ ?array $ extensionASTNodes = null
35+ ) {
36+ $ this ->enumClass = $ enumClass ;
37+ $ reflection = new \ReflectionEnum ($ enumClass );
2938
3039 /**
3140 * @var array<string, PartialEnumValueConfig> $enumDefinitions
@@ -40,9 +49,11 @@ public function __construct(string $enum, ?string $name = null)
4049 }
4150
4251 parent ::__construct ([
43- 'name ' => $ name ?? $ this ->baseName ($ enum ),
52+ 'name ' => $ name ?? $ this ->baseName ($ enumClass ),
4453 'values ' => $ enumDefinitions ,
45- 'description ' => $ this ->extractDescription ($ reflection ),
54+ 'description ' => $ description ?? $ this ->extractDescription ($ reflection ),
55+ 'astNode ' => $ astNode ,
56+ 'extensionASTNodes ' => $ extensionASTNodes ,
4657 ]);
4758 }
4859
0 commit comments