Skip to content

Commit c1c9e5b

Browse files
authoredOct 26, 2024··
Allow customizing PhpEnumType
1 parent 088f24d commit c1c9e5b

14 files changed

+112
-67
lines changed
 

‎CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ You can find and compare releases at the [GitHub release page](https://github.co
99

1010
## Unreleased
1111

12+
## v15.17.0
13+
14+
### Added
15+
16+
- Allow customizing PhpEnumType https://github.com/webonyx/graphql-php/pull/1623
17+
1218
## v15.16.1
1319

1420
### Fixed

‎src/Type/Definition/EnumType.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* description?: string|null,
3131
* values: EnumValues|callable(): EnumValues,
3232
* astNode?: EnumTypeDefinitionNode|null,
33-
* extensionASTNodes?: array<int, EnumTypeExtensionNode>|null
33+
* extensionASTNodes?: array<EnumTypeExtensionNode>|null
3434
* }
3535
*/
3636
class EnumType extends Type implements InputType, OutputType, LeafType, NullableType, NamedType
@@ -39,7 +39,7 @@ class EnumType extends Type implements InputType, OutputType, LeafType, Nullable
3939

4040
public ?EnumTypeDefinitionNode $astNode;
4141

42-
/** @var array<int, EnumTypeExtensionNode> */
42+
/** @var array<EnumTypeExtensionNode> */
4343
public array $extensionASTNodes;
4444

4545
/** @phpstan-var EnumTypeConfig */
@@ -264,7 +264,7 @@ public function astNode(): ?EnumTypeDefinitionNode
264264
return $this->astNode;
265265
}
266266

267-
/** @return array<int, EnumTypeExtensionNode> */
267+
/** @return array<EnumTypeExtensionNode> */
268268
public function extensionASTNodes(): array
269269
{
270270
return $this->extensionASTNodes;

‎src/Type/Definition/InputObjectType.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* fields: iterable<FieldConfig>|callable(): iterable<FieldConfig>,
2121
* parseValue?: callable(array<string, mixed>): mixed,
2222
* astNode?: InputObjectTypeDefinitionNode|null,
23-
* extensionASTNodes?: array<int, InputObjectTypeExtensionNode>|null
23+
* extensionASTNodes?: array<InputObjectTypeExtensionNode>|null
2424
* }
2525
*/
2626
class InputObjectType extends Type implements InputType, NullableType, NamedType
@@ -29,7 +29,7 @@ class InputObjectType extends Type implements InputType, NullableType, NamedType
2929

3030
public ?InputObjectTypeDefinitionNode $astNode;
3131

32-
/** @var array<int, InputObjectTypeExtensionNode> */
32+
/** @var array<InputObjectTypeExtensionNode> */
3333
public array $extensionASTNodes;
3434

3535
/** @phpstan-var InputObjectConfig */
@@ -203,7 +203,7 @@ public function astNode(): ?InputObjectTypeDefinitionNode
203203
return $this->astNode;
204204
}
205205

206-
/** @return array<int, InputObjectTypeExtensionNode> */
206+
/** @return array<InputObjectTypeExtensionNode> */
207207
public function extensionASTNodes(): array
208208
{
209209
return $this->extensionASTNodes;

‎src/Type/Definition/InterfaceType.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* interfaces?: iterable<InterfaceTypeReference>|callable(): iterable<InterfaceTypeReference>,
2121
* resolveType?: ResolveType|null,
2222
* astNode?: InterfaceTypeDefinitionNode|null,
23-
* extensionASTNodes?: array<int, InterfaceTypeExtensionNode>|null
23+
* extensionASTNodes?: array<InterfaceTypeExtensionNode>|null
2424
* }
2525
*/
2626
class InterfaceType extends Type implements AbstractType, OutputType, CompositeType, NullableType, HasFieldsType, NamedType, ImplementingType
@@ -31,7 +31,7 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
3131

3232
public ?InterfaceTypeDefinitionNode $astNode;
3333

34-
/** @var array<int, InterfaceTypeExtensionNode> */
34+
/** @var array<InterfaceTypeExtensionNode> */
3535
public array $extensionASTNodes;
3636

3737
/** @phpstan-var InterfaceConfig */
@@ -99,7 +99,7 @@ public function astNode(): ?InterfaceTypeDefinitionNode
9999
return $this->astNode;
100100
}
101101

102-
/** @return array<int, InterfaceTypeExtensionNode> */
102+
/** @return array<InterfaceTypeExtensionNode> */
103103
public function extensionASTNodes(): array
104104
{
105105
return $this->extensionASTNodes;

‎src/Type/Definition/NamedType.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @property string $name
2020
* @property string|null $description
2121
* @property (Node&TypeDefinitionNode)|null $astNode
22-
* @property array<int, Node&TypeExtensionNode> $extensionASTNodes
22+
* @property array<Node&TypeExtensionNode> $extensionASTNodes
2323
*/
2424
interface NamedType
2525
{
@@ -36,6 +36,6 @@ public function description(): ?string;
3636
/** @return (Node&TypeDefinitionNode)|null */
3737
public function astNode(): ?Node;
3838

39-
/** @return array<int, Node&TypeExtensionNode> */
39+
/** @return array<Node&TypeExtensionNode> */
4040
public function extensionASTNodes(): array;
4141
}

‎src/Type/Definition/ObjectType.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
* interfaces?: iterable<InterfaceTypeReference>|callable(): iterable<InterfaceTypeReference>,
6363
* isTypeOf?: (callable(mixed $objectValue, mixed $context, ResolveInfo $resolveInfo): (bool|Deferred|null))|null,
6464
* astNode?: ObjectTypeDefinitionNode|null,
65-
* extensionASTNodes?: array<int, ObjectTypeExtensionNode>|null
65+
* extensionASTNodes?: array<ObjectTypeExtensionNode>|null
6666
* }
6767
*/
6868
class ObjectType extends Type implements OutputType, CompositeType, NullableType, HasFieldsType, NamedType, ImplementingType
@@ -73,7 +73,7 @@ class ObjectType extends Type implements OutputType, CompositeType, NullableType
7373

7474
public ?ObjectTypeDefinitionNode $astNode;
7575

76-
/** @var array<int, ObjectTypeExtensionNode> */
76+
/** @var array<ObjectTypeExtensionNode> */
7777
public array $extensionASTNodes;
7878

7979
/**
@@ -172,7 +172,7 @@ public function astNode(): ?ObjectTypeDefinitionNode
172172
return $this->astNode;
173173
}
174174

175-
/** @return array<int, ObjectTypeExtensionNode> */
175+
/** @return array<ObjectTypeExtensionNode> */
176176
public function extensionASTNodes(): array
177177
{
178178
return $this->extensionASTNodes;

‎src/Type/Definition/PhpEnumType.php

+18-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace GraphQL\Type\Definition;
44

55
use GraphQL\Error\SerializationError;
6+
use GraphQL\Language\AST\EnumTypeDefinitionNode;
7+
use GraphQL\Language\AST\EnumTypeExtensionNode;
68
use GraphQL\Utils\PhpDoc;
79
use 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

‎src/Type/Definition/ScalarType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function astNode(): ?ScalarTypeDefinitionNode
6969
return $this->astNode;
7070
}
7171

72-
/** @return array<int, ScalarTypeExtensionNode> */
72+
/** @return array<ScalarTypeExtensionNode> */
7373
public function extensionASTNodes(): array
7474
{
7575
return $this->extensionASTNodes;

‎src/Type/Definition/UnionType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function astNode(): ?UnionTypeDefinitionNode
132132
return $this->astNode;
133133
}
134134

135-
/** @return array<int, UnionTypeExtensionNode> */
135+
/** @return array<UnionTypeExtensionNode> */
136136
public function extensionASTNodes(): array
137137
{
138138
return $this->extensionASTNodes;

‎src/Type/Schema.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class Schema
7171

7272
public ?SchemaDefinitionNode $astNode;
7373

74-
/** @var array<int, SchemaExtensionNode> */
74+
/** @var array<SchemaExtensionNode> */
7575
public array $extensionASTNodes = [];
7676

7777
/**

‎src/Type/SchemaValidationContext.php

+17-19
Original file line numberDiff line numberDiff line change
@@ -386,36 +386,38 @@ private function validateFields(Type $type): void
386386
/**
387387
* @param Schema|ObjectType|InterfaceType|UnionType|EnumType|InputObjectType|Directive $obj
388388
*
389-
* @return array<int, SchemaDefinitionNode|SchemaExtensionNode>|array<int, ObjectTypeDefinitionNode|ObjectTypeExtensionNode>|array<int, InterfaceTypeDefinitionNode|InterfaceTypeExtensionNode>|array<int, UnionTypeDefinitionNode|UnionTypeExtensionNode>|array<int, EnumTypeDefinitionNode|EnumTypeExtensionNode>|array<int, InputObjectTypeDefinitionNode|InputObjectTypeExtensionNode>|array<int, DirectiveDefinitionNode>
389+
* @return list<SchemaDefinitionNode|SchemaExtensionNode>|list<ObjectTypeDefinitionNode|ObjectTypeExtensionNode>|list<InterfaceTypeDefinitionNode|InterfaceTypeExtensionNode>|list<UnionTypeDefinitionNode|UnionTypeExtensionNode>|list< EnumTypeDefinitionNode|EnumTypeExtensionNode>|list<InputObjectTypeDefinitionNode|InputObjectTypeExtensionNode>|list<DirectiveDefinitionNode>
390390
*/
391391
private function getAllNodes(object $obj): array
392392
{
393+
$astNode = $obj->astNode;
394+
393395
if ($obj instanceof Schema) {
394-
$astNode = $obj->astNode;
395396
$extensionNodes = $obj->extensionASTNodes;
396397
} elseif ($obj instanceof Directive) {
397-
$astNode = $obj->astNode;
398398
$extensionNodes = [];
399399
} else {
400-
$astNode = $obj->astNode;
401400
$extensionNodes = $obj->extensionASTNodes;
402401
}
403402

404-
return $astNode !== null
405-
? \array_merge([$astNode], $extensionNodes)
406-
: $extensionNodes;
403+
$allNodes = $astNode === null
404+
? []
405+
: [$astNode];
406+
foreach ($extensionNodes as $extensionNode) {
407+
$allNodes[] = $extensionNode;
408+
}
409+
410+
return $allNodes;
407411
}
408412

409413
/**
410414
* @param ObjectType|InterfaceType $type
411415
*
412-
* @return array<int, FieldDefinitionNode>
416+
* @return list<FieldDefinitionNode>
413417
*/
414418
private function getAllFieldNodes(Type $type, string $fieldName): array
415419
{
416-
$allNodes = $type->astNode !== null
417-
? \array_merge([$type->astNode], $type->extensionASTNodes)
418-
: $type->extensionASTNodes;
420+
$allNodes = array_filter([$type->astNode, ...$type->extensionASTNodes]);
419421

420422
$matchingFieldNodes = [];
421423

@@ -574,13 +576,11 @@ private function getImplementsInterfaceNode(ImplementingType $type, NamedType $s
574576
* @param ObjectType|InterfaceType $type
575577
* @param Type&NamedType $shouldBeInterface
576578
*
577-
* @return array<int, NamedTypeNode>
579+
* @return list<NamedTypeNode>
578580
*/
579581
private function getAllImplementsInterfaceNodes(ImplementingType $type, NamedType $shouldBeInterface): array
580582
{
581-
$allNodes = $type->astNode !== null
582-
? \array_merge([$type->astNode], $type->extensionASTNodes)
583-
: $type->extensionASTNodes;
583+
$allNodes = array_filter([$type->astNode, ...$type->extensionASTNodes]);
584584

585585
$shouldBeInterfaceName = $shouldBeInterface->name;
586586
$matchingInterfaceNodes = [];
@@ -735,12 +735,10 @@ private function validateUnionMembers(UnionType $union): void
735735
}
736736
}
737737

738-
/** @return array<int, NamedTypeNode> */
738+
/** @return list<NamedTypeNode> */
739739
private function getUnionMemberTypeNodes(UnionType $union, string $typeName): array
740740
{
741-
$allNodes = $union->astNode !== null
742-
? \array_merge([$union->astNode], $union->extensionASTNodes)
743-
: $union->extensionASTNodes;
741+
$allNodes = array_filter([$union->astNode, ...$union->extensionASTNodes]);
744742

745743
$types = [];
746744
foreach ($allNodes as $node) {

‎src/Utils/ASTDefinitionBuilder.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ private function makeSchemaDef(Node $def): Type
339339
private function makeTypeDef(ObjectTypeDefinitionNode $def): ObjectType
340340
{
341341
$name = $def->name->value;
342-
/** @var array<int, ObjectTypeExtensionNode> $extensionASTNodes (proven by schema validation) */
342+
/** @var array<ObjectTypeExtensionNode> $extensionASTNodes (proven by schema validation) */
343343
$extensionASTNodes = $this->typeExtensionsMap[$name] ?? [];
344344
$allNodes = [$def, ...$extensionASTNodes];
345345

@@ -453,7 +453,7 @@ private function makeImplementedInterfaces(array $nodes): array
453453
private function makeInterfaceDef(InterfaceTypeDefinitionNode $def): InterfaceType
454454
{
455455
$name = $def->name->value;
456-
/** @var array<int, InterfaceTypeExtensionNode> $extensionASTNodes (proven by schema validation) */
456+
/** @var array<InterfaceTypeExtensionNode> $extensionASTNodes (proven by schema validation) */
457457
$extensionASTNodes = $this->typeExtensionsMap[$name] ?? [];
458458
$allNodes = [$def, ...$extensionASTNodes];
459459

@@ -475,7 +475,7 @@ private function makeInterfaceDef(InterfaceTypeDefinitionNode $def): InterfaceTy
475475
private function makeEnumDef(EnumTypeDefinitionNode $def): EnumType
476476
{
477477
$name = $def->name->value;
478-
/** @var array<int, EnumTypeExtensionNode> $extensionASTNodes (proven by schema validation) */
478+
/** @var array<EnumTypeExtensionNode> $extensionASTNodes (proven by schema validation) */
479479
$extensionASTNodes = $this->typeExtensionsMap[$name] ?? [];
480480

481481
$values = [];
@@ -502,7 +502,7 @@ private function makeEnumDef(EnumTypeDefinitionNode $def): EnumType
502502
private function makeUnionDef(UnionTypeDefinitionNode $def): UnionType
503503
{
504504
$name = $def->name->value;
505-
/** @var array<int, UnionTypeExtensionNode> $extensionASTNodes (proven by schema validation) */
505+
/** @var array<UnionTypeExtensionNode> $extensionASTNodes (proven by schema validation) */
506506
$extensionASTNodes = $this->typeExtensionsMap[$name] ?? [];
507507

508508
return new UnionType([
@@ -531,23 +531,23 @@ private function makeUnionDef(UnionTypeDefinitionNode $def): UnionType
531531
private function makeScalarDef(ScalarTypeDefinitionNode $def): CustomScalarType
532532
{
533533
$name = $def->name->value;
534-
/** @var array<int, ScalarTypeExtensionNode> $extensionASTNodes (proven by schema validation) */
534+
/** @var array<ScalarTypeExtensionNode> $extensionASTNodes (proven by schema validation) */
535535
$extensionASTNodes = $this->typeExtensionsMap[$name] ?? [];
536536

537537
return new CustomScalarType([
538538
'name' => $name,
539539
'description' => $def->description->value ?? null,
540+
'serialize' => static fn ($value) => $value,
540541
'astNode' => $def,
541542
'extensionASTNodes' => $extensionASTNodes,
542-
'serialize' => static fn ($value) => $value,
543543
]);
544544
}
545545

546546
/** @throws InvariantViolation */
547547
private function makeInputObjectDef(InputObjectTypeDefinitionNode $def): InputObjectType
548548
{
549549
$name = $def->name->value;
550-
/** @var array<int, InputObjectTypeExtensionNode> $extensionASTNodes (proven by schema validation) */
550+
/** @var array<InputObjectTypeExtensionNode> $extensionASTNodes (proven by schema validation) */
551551
$extensionASTNodes = $this->typeExtensionsMap[$name] ?? [];
552552

553553
return new InputObjectType([

‎src/Utils/SchemaExtender.php

+15-17
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,7 @@ function (string $typeName) use ($schema): Type {
188188
}
189189
}
190190

191-
$schemaExtensionASTNodes = \array_merge($schema->extensionASTNodes, $schemaExtensions);
192-
193-
return new Schema(
194-
(new SchemaConfig())
191+
$schemaConfig = (new SchemaConfig())
195192
// @phpstan-ignore-next-line the root types may be invalid, but just passing them leads to more actionable errors
196193
->setQuery($operationTypes['query'])
197194
// @phpstan-ignore-next-line the root types may be invalid, but just passing them leads to more actionable errors
@@ -201,8 +198,9 @@ function (string $typeName) use ($schema): Type {
201198
->setTypes($types)
202199
->setDirectives($this->getMergedDirectives($schema, $directiveDefinitions))
203200
->setAstNode($schema->astNode ?? $schemaDef)
204-
->setExtensionASTNodes($schemaExtensionASTNodes)
205-
);
201+
->setExtensionASTNodes([...$schema->extensionASTNodes, ...$schemaExtensions]);
202+
203+
return new Schema($schemaConfig);
206204
}
207205

208206
/**
@@ -212,10 +210,10 @@ function (string $typeName) use ($schema): Type {
212210
*/
213211
protected function extensionASTNodes(NamedType $type): ?array
214212
{
215-
return \array_merge(
216-
$type->extensionASTNodes ?? [],
217-
$this->typeExtensionsMap[$type->name] ?? []
218-
);
213+
return [
214+
...$type->extensionASTNodes ?? [],
215+
...$this->typeExtensionsMap[$type->name] ?? [],
216+
];
219217
}
220218

221219
/**
@@ -225,7 +223,7 @@ protected function extensionASTNodes(NamedType $type): ?array
225223
*/
226224
protected function extendScalarType(ScalarType $type): CustomScalarType
227225
{
228-
/** @var array<int, ScalarTypeExtensionNode> $extensionASTNodes */
226+
/** @var array<ScalarTypeExtensionNode> $extensionASTNodes */
229227
$extensionASTNodes = $this->extensionASTNodes($type);
230228

231229
return new CustomScalarType([
@@ -242,7 +240,7 @@ protected function extendScalarType(ScalarType $type): CustomScalarType
242240
/** @throws InvariantViolation */
243241
protected function extendUnionType(UnionType $type): UnionType
244242
{
245-
/** @var array<int, UnionTypeExtensionNode> $extensionASTNodes */
243+
/** @var array<UnionTypeExtensionNode> $extensionASTNodes */
246244
$extensionASTNodes = $this->extensionASTNodes($type);
247245

248246
return new UnionType([
@@ -262,7 +260,7 @@ protected function extendUnionType(UnionType $type): UnionType
262260
*/
263261
protected function extendEnumType(EnumType $type): EnumType
264262
{
265-
/** @var array<int, EnumTypeExtensionNode> $extensionASTNodes */
263+
/** @var array<EnumTypeExtensionNode> $extensionASTNodes */
266264
$extensionASTNodes = $this->extensionASTNodes($type);
267265

268266
return new EnumType([
@@ -277,16 +275,16 @@ protected function extendEnumType(EnumType $type): EnumType
277275
/** @throws InvariantViolation */
278276
protected function extendInputObjectType(InputObjectType $type): InputObjectType
279277
{
280-
/** @var array<int, InputObjectTypeExtensionNode> $extensionASTNodes */
278+
/** @var array<InputObjectTypeExtensionNode> $extensionASTNodes */
281279
$extensionASTNodes = $this->extensionASTNodes($type);
282280

283281
return new InputObjectType([
284282
'name' => $type->name,
285283
'description' => $type->description,
286284
'fields' => fn (): array => $this->extendInputFieldMap($type),
285+
'parseValue' => [$type, 'parseValue'],
287286
'astNode' => $type->astNode,
288287
'extensionASTNodes' => $extensionASTNodes,
289-
'parseValue' => [$type, 'parseValue'],
290288
]);
291289
}
292290

@@ -529,7 +527,7 @@ protected function extendFieldMap(Type $type): array
529527
/** @throws InvariantViolation */
530528
protected function extendObjectType(ObjectType $type): ObjectType
531529
{
532-
/** @var array<int, ObjectTypeExtensionNode> $extensionASTNodes */
530+
/** @var array<ObjectTypeExtensionNode> $extensionASTNodes */
533531
$extensionASTNodes = $this->extensionASTNodes($type);
534532

535533
return new ObjectType([
@@ -548,7 +546,7 @@ protected function extendObjectType(ObjectType $type): ObjectType
548546
/** @throws InvariantViolation */
549547
protected function extendInterfaceType(InterfaceType $type): InterfaceType
550548
{
551-
/** @var array<int, InterfaceTypeExtensionNode> $extensionASTNodes */
549+
/** @var array<InterfaceTypeExtensionNode> $extensionASTNodes */
552550
$extensionASTNodes = $this->extensionASTNodes($type);
553551

554552
return new InterfaceType([

‎tests/Type/PhpEnumTypeTest.php

+32
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use GraphQL\Error\DebugFlag;
66
use GraphQL\Error\SerializationError;
77
use GraphQL\GraphQL;
8+
use GraphQL\Language\Parser;
89
use GraphQL\Tests\TestCaseBase;
910
use GraphQL\Tests\Type\PhpEnumType\DocBlockPhpEnum;
1011
use GraphQL\Tests\Type\PhpEnumType\IntPhpEnum;
@@ -44,6 +45,37 @@ enum PhpEnum {
4445
GRAPHQL, SchemaPrinter::printType($enumType));
4546
}
4647

48+
public function testConstructEnumTypeFromPhpEnumWithOverwrittenDefaults(): void
49+
{
50+
$astNode = Parser::enumTypeDefinition(<<<'GRAPHQL'
51+
enum MyEnum @directiveA
52+
GRAPHQL);
53+
$extensionASTNode1 = Parser::enumTypeExtension(<<<'GRAPHQL'
54+
extend enum MyEnum @directiveB
55+
GRAPHQL);
56+
$extensionASTNode2 = Parser::enumTypeExtension(<<<'GRAPHQL'
57+
extend enum MyEnum @directiveC
58+
GRAPHQL);
59+
$enumType = new PhpEnumType(
60+
PhpEnum::class,
61+
'MyEnum',
62+
'My description.',
63+
$astNode,
64+
[$extensionASTNode1, $extensionASTNode2]
65+
);
66+
self::assertSame(<<<'GRAPHQL'
67+
"My description."
68+
enum MyEnum {
69+
"bar"
70+
A
71+
B @deprecated
72+
C @deprecated(reason: "baz")
73+
}
74+
GRAPHQL, SchemaPrinter::printType($enumType));
75+
self::assertSame($astNode, $enumType->astNode);
76+
self::assertSame([$extensionASTNode1, $extensionASTNode2], $enumType->extensionASTNodes);
77+
}
78+
4779
public function testConstructEnumTypeFromIntPhpEnum(): void
4880
{
4981
$enumType = new PhpEnumType(IntPhpEnum::class);

0 commit comments

Comments
 (0)
Please sign in to comment.