|
14 | 14 | use Jerowork\GraphqlAttributeSchema\Parser\Node\Type\ScalarNodeType; |
15 | 15 | use Jerowork\GraphqlAttributeSchema\TypeBuilder\Object\ObjectTypeBuilder; |
16 | 16 |
|
17 | | -final class TypeBuilder |
| 17 | +final readonly class TypeBuilder |
18 | 18 | { |
19 | | - /** |
20 | | - * @var array<class-string, WebonyxType> |
21 | | - */ |
22 | | - private array $builtTypes = []; |
23 | | - |
24 | 19 | /** |
25 | 20 | * @param iterable<ObjectTypeBuilder<Node>> $objectTypeBuilders |
26 | 21 | */ |
27 | 22 | public function __construct( |
28 | | - private readonly iterable $objectTypeBuilders, |
| 23 | + private BuiltTypesRegistry $builtTypesRegistry, |
| 24 | + private iterable $objectTypeBuilders, |
29 | 25 | ) {} |
30 | 26 |
|
31 | 27 | /** |
@@ -95,18 +91,20 @@ private function buildObject(string $className, Ast $ast): WebonyxType |
95 | 91 | $nodeClassName = $node->getClassName(); |
96 | 92 | } |
97 | 93 |
|
98 | | - if (array_key_exists($nodeClassName, $this->builtTypes)) { |
99 | | - return $this->builtTypes[$nodeClassName]; |
| 94 | + if ($this->builtTypesRegistry->hasType($nodeClassName)) { |
| 95 | + return $this->builtTypesRegistry->getType($nodeClassName); |
100 | 96 | } |
101 | 97 |
|
102 | 98 | foreach ($this->objectTypeBuilders as $objectTypeBuilder) { |
103 | 99 | if (!$objectTypeBuilder->supports($node)) { |
104 | 100 | continue; |
105 | 101 | } |
106 | 102 |
|
107 | | - $this->builtTypes[$nodeClassName] = $objectTypeBuilder->build($node, $this, $ast); |
| 103 | + $builtType = $objectTypeBuilder->build($node, $this, $ast); |
| 104 | + |
| 105 | + $this->builtTypesRegistry->addType($nodeClassName, $builtType); |
108 | 106 |
|
109 | | - return $this->builtTypes[$nodeClassName]; |
| 107 | + return $builtType; |
110 | 108 | } |
111 | 109 |
|
112 | 110 | throw BuildException::logicError(sprintf('Invalid object class %s', $nodeClassName)); |
|
0 commit comments