Skip to content

Commit 547f00c

Browse files
committed
Use base type enum
1 parent 0377048 commit 547f00c

File tree

14 files changed

+67
-32
lines changed

14 files changed

+67
-32
lines changed

src/Config/Parser/GraphQL/ASTConverter/CustomScalarNode.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter;
66

77
use GraphQL\Language\AST\Node;
8+
use Overblog\GraphQLBundle\Enum\TypeEnum;
89
use RuntimeException;
910

1011
class CustomScalarNode implements NodeInterface
@@ -19,7 +20,7 @@ public static function toConfig(Node $node): array
1920
];
2021

2122
return [
22-
'type' => 'custom-scalar',
23+
'type' => TypeEnum::CUSTOM_SCALAR,
2324
'config' => $config,
2425
];
2526
}

src/Config/Parser/GraphQL/ASTConverter/EnumNode.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter;
66

77
use GraphQL\Language\AST\Node;
8+
use Overblog\GraphQLBundle\Enum\TypeEnum;
89

910
class EnumNode implements NodeInterface
1011
{
@@ -28,7 +29,7 @@ public static function toConfig(Node $node): array
2829
$config['values'] = $values;
2930

3031
return [
31-
'type' => 'enum',
32+
'type' => TypeEnum::ENUM,
3233
'config' => $config,
3334
];
3435
}

src/Config/Parser/GraphQL/ASTConverter/InputObjectNode.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter;
66

7+
use Overblog\GraphQLBundle\Enum\TypeEnum;
8+
79
class InputObjectNode extends ObjectNode
810
{
9-
protected const TYPENAME = 'input-object';
11+
protected const TYPENAME = TypeEnum::INPUT_OBJECT;
1012
}

src/Config/Parser/GraphQL/ASTConverter/InterfaceNode.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter;
66

7+
use Overblog\GraphQLBundle\Enum\TypeEnum;
8+
79
class InterfaceNode extends ObjectNode
810
{
9-
protected const TYPENAME = 'interface';
11+
protected const TYPENAME = TypeEnum::INTERFACE;
1012
}

src/Config/Parser/GraphQL/ASTConverter/ObjectNode.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
use GraphQL\Language\AST\Node;
88
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
9+
use Overblog\GraphQLBundle\Enum\TypeEnum;
910

1011
class ObjectNode implements NodeInterface
1112
{
12-
protected const TYPENAME = 'object';
13+
protected const TYPENAME = TypeEnum::OBJECT;
1314

1415
public static function toConfig(Node $node): array
1516
{

src/Config/Parser/GraphQL/ASTConverter/UnionNode.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter;
66

77
use GraphQL\Language\AST\Node;
8+
use Overblog\GraphQLBundle\Enum\TypeEnum;
89

910
class UnionNode implements NodeInterface
1011
{
@@ -21,7 +22,7 @@ public static function toConfig(Node $node): array
2122
}
2223

2324
return [
24-
'type' => 'union',
25+
'type' => TypeEnum::UNION,
2526
'config' => $config,
2627
];
2728
}

src/Config/Parser/MetadataParser/MetadataParser.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Overblog\GraphQLBundle\Config\Parser\MetadataParser\TypeGuesser\TypeGuessingException;
1313
use Overblog\GraphQLBundle\Config\Parser\MetadataParser\TypeGuesser\TypeHintTypeGuesser;
1414
use Overblog\GraphQLBundle\Config\Parser\PreParserInterface;
15+
use Overblog\GraphQLBundle\Enum\TypeEnum;
1516
use Overblog\GraphQLBundle\Relay\Connection\ConnectionInterface;
1617
use Overblog\GraphQLBundle\Relay\Connection\EdgeInterface;
1718
use ReflectionClass;
@@ -169,7 +170,7 @@ private static function classMetadatasToGQLConfiguration(
169170
if (!$edgeType) {
170171
$edgeType = $gqlName.'Edge';
171172
$gqlTypes[$edgeType] = [
172-
'type' => 'object',
173+
'type' => TypeEnum::OBJECT,
173174
'config' => [
174175
'builders' => [
175176
['builder' => 'relay-edge', 'builderConfig' => ['nodeType' => $classMetadata->node]],
@@ -397,7 +398,7 @@ private static function inputMetadataToGQLConfiguration(ReflectionClass $reflect
397398
'fields' => self::getGraphQLInputFieldsFromMetadatas($reflectionClass, self::getClassProperties($reflectionClass)),
398399
], self::getDescriptionConfiguration(static::getMetadatas($reflectionClass)));
399400

400-
return ['type' => $inputAnnotation->isRelay ? 'relay-mutation-input' : 'input-object', 'config' => $inputConfiguration];
401+
return ['type' => $inputAnnotation->isRelay ? 'relay-mutation-input' : TypeEnum::INPUT_OBJECT, 'config' => $inputConfiguration];
401402
}
402403

403404
/**
@@ -421,7 +422,7 @@ private static function scalarMetadataToGQLConfiguration(ReflectionClass $reflec
421422

422423
$scalarConfiguration = self::getDescriptionConfiguration(static::getMetadatas($reflectionClass)) + $scalarConfiguration;
423424

424-
return ['type' => 'custom-scalar', 'config' => $scalarConfiguration];
425+
return ['type' => TypeEnum::CUSTOM_SCALAR, 'config' => $scalarConfiguration];
425426
}
426427

427428
/**
@@ -459,7 +460,7 @@ private static function enumMetadataToGQLConfiguration(ReflectionClass $reflecti
459460
$enumConfiguration = ['values' => $values];
460461
$enumConfiguration = self::getDescriptionConfiguration(static::getMetadatas($reflectionClass)) + $enumConfiguration;
461462

462-
return ['type' => 'enum', 'config' => $enumConfiguration];
463+
return ['type' => TypeEnum::ENUM, 'config' => $enumConfiguration];
463464
}
464465

465466
/**
@@ -504,7 +505,7 @@ private static function unionMetadataToGQLConfiguration(ReflectionClass $reflect
504505
}
505506
}
506507

507-
return ['type' => 'union', 'config' => $unionConfiguration];
508+
return ['type' => TypeEnum::UNION, 'config' => $unionConfiguration];
508509
}
509510

510511
/**

src/Config/Processor/InheritanceProcessor.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Exception;
88
use InvalidArgumentException;
9+
use Overblog\GraphQLBundle\Enum\TypeEnum;
910
use function array_column;
1011
use function array_filter;
1112
use function array_flip;
@@ -80,8 +81,8 @@ private static function processConfigsInherits(array $configs): array
8081
}
8182

8283
$allowedTypes = [$config['type']];
83-
if ('object' === $config['type']) {
84-
$allowedTypes[] = 'interface';
84+
if (TypeEnum::OBJECT === $config['type']) {
85+
$allowedTypes[] = TypeEnum::INTERFACE;
8586
}
8687
$flattenInherits = self::flattenInherits($name, $configs, $allowedTypes);
8788
if (empty($flattenInherits)) {
@@ -106,7 +107,7 @@ private static function inheritsTypeConfig(string $child, array $parents, array
106107
$mergedParentsConfig = self::mergeConfigs(...array_column($parentTypes, 'config'));
107108
$childType = $configs[$child];
108109
// unset resolveType field resulting from the merge of a "interface" type
109-
if ('object' === $childType['type']) {
110+
if (TypeEnum::OBJECT === $childType['type']) {
110111
unset($mergedParentsConfig['resolveType']);
111112
}
112113

src/DependencyInjection/TypesConfiguration.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Overblog\GraphQLBundle\Config;
88
use Overblog\GraphQLBundle\Config\Processor\InheritanceProcessor;
9+
use Overblog\GraphQLBundle\Enum\TypeEnum;
910
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1011
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1112
use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -22,12 +23,12 @@
2223
class TypesConfiguration implements ConfigurationInterface
2324
{
2425
private static array $types = [
25-
'object',
26-
'enum',
27-
'interface',
28-
'union',
29-
'input-object',
30-
'custom-scalar',
26+
TypeEnum::OBJECT,
27+
TypeEnum::ENUM,
28+
TypeEnum::INTERFACE,
29+
TypeEnum::UNION,
30+
TypeEnum::INPUT_OBJECT,
31+
TypeEnum::CUSTOM_SCALAR,
3132
];
3233

3334
public function getConfigTreeBuilder(): TreeBuilder

src/Enum/TypeEnum.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Overblog\GraphQLBundle\Enum;
6+
7+
class TypeEnum
8+
{
9+
public const OBJECT = 'object';
10+
public const INPUT_OBJECT = 'input-object';
11+
public const INTERFACE = 'interface';
12+
public const UNION = 'union';
13+
public const ENUM = 'enum';
14+
public const CUSTOM_SCALAR = 'custom-scalar';
15+
16+
private function __construct()
17+
{
18+
// forbid creation of an object
19+
}
20+
}

0 commit comments

Comments
 (0)