3
3
namespace GraphQL \Type \Definition ;
4
4
5
5
use GraphQL \Error \SerializationError ;
6
+ use GraphQL \Language \AST \EnumTypeDefinitionNode ;
7
+ use GraphQL \Language \AST \EnumTypeExtensionNode ;
6
8
use GraphQL \Utils \PhpDoc ;
7
9
use GraphQL \Utils \Utils ;
8
10
@@ -16,16 +18,23 @@ class PhpEnumType extends EnumType
16
18
protected string $ enumClass ;
17
19
18
20
/**
19
- * @param class-string<\UnitEnum> $enum
21
+ * @param class-string<\UnitEnum> $enumClass The fully qualified class name of a native PHP enum
20
22
* @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
21
25
*
22
26
* @throws \Exception
23
27
* @throws \ReflectionException
24
28
*/
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 );
29
38
30
39
/**
31
40
* @var array<string, PartialEnumValueConfig> $enumDefinitions
@@ -40,9 +49,11 @@ public function __construct(string $enum, ?string $name = null)
40
49
}
41
50
42
51
parent ::__construct ([
43
- 'name ' => $ name ?? $ this ->baseName ($ enum ),
52
+ 'name ' => $ name ?? $ this ->baseName ($ enumClass ),
44
53
'values ' => $ enumDefinitions ,
45
- 'description ' => $ this ->extractDescription ($ reflection ),
54
+ 'description ' => $ description ?? $ this ->extractDescription ($ reflection ),
55
+ 'astNode ' => $ astNode ,
56
+ 'extensionASTNodes ' => $ extensionASTNodes ,
46
57
]);
47
58
}
48
59
0 commit comments