|
13 | 13 | use GraphQL\Language\Printer; |
14 | 14 | use GraphQL\Type\Definition\EnumType; |
15 | 15 | use GraphQL\Type\Definition\InputObjectType; |
16 | | -use GraphQL\Type\Definition\InterfaceType; |
17 | | -use GraphQL\Type\Definition\NonNull; |
18 | 16 | use GraphQL\Type\Definition\Type; |
19 | | -use GraphQL\Type\Definition\UnionType; |
20 | 17 | use GraphQL\Type\Schema; |
21 | 18 | use GraphQL\Validator\DocumentValidator; |
22 | 19 | use GraphQL\Validator\Rules\ExecutableDefinitions; |
|
56 | 53 | use GraphQL\Validator\Rules\VariablesAreInputTypes; |
57 | 54 | use GraphQL\Validator\Rules\VariablesInAllowedPosition; |
58 | 55 | use JsonException; |
| 56 | +use Ruudk\GraphQLCodeGenerator\GraphQL\PossibleTypesFinder; |
59 | 57 | use Ruudk\GraphQLCodeGenerator\Planner\OperationPlan; |
60 | 58 | use Ruudk\GraphQLCodeGenerator\Planner\Plan\DataClassPlan; |
61 | 59 | use Ruudk\GraphQLCodeGenerator\Planner\Plan\EnumClassPlan; |
@@ -110,6 +108,7 @@ final class Planner |
110 | 108 | private TypeMapper $typeMapper; |
111 | 109 | private DirectiveProcessor $directiveProcessor; |
112 | 110 | private VariableParser $variableParser; |
| 111 | + private PossibleTypesFinder $possibleTypesFinder; |
113 | 112 |
|
114 | 113 | /** |
115 | 114 | * @throws \GraphQL\Error\Error |
@@ -137,6 +136,7 @@ public function __construct( |
137 | 136 | $this->schemaLoader = new SchemaLoader(new Filesystem()); |
138 | 137 | $this->schema = $this->schemaLoader->load($config->schema, $config->indexByDirective); |
139 | 138 | $this->optimizer = new Optimizer($this->schema); |
| 139 | + $this->possibleTypesFinder = new PossibleTypesFinder($this->schema); |
140 | 140 |
|
141 | 141 | $this->validatorRules = [ |
142 | 142 | ExecutableDefinitions::class => new ExecutableDefinitions(), |
@@ -396,7 +396,7 @@ public function plan() : PlannerResult |
396 | 396 | parentType: $type, |
397 | 397 | fields: $planResult->fields, |
398 | 398 | payloadShape: $planResult->payloadShape, |
399 | | - possibleTypes: $this->getPossibleTypes($type), |
| 399 | + possibleTypes: $this->possibleTypesFinder->find($type), |
400 | 400 | definitionNode: $fragment, |
401 | 401 | nodesType: null, |
402 | 402 | inlineFragmentRequiredFields: $planResult->inlineFragmentRequiredFields, |
@@ -573,35 +573,4 @@ private function fullyQualified(string $part, string ...$moreParts) : string |
573 | 573 |
|
574 | 574 | return implode('\\', array_filter([$this->config->namespace, $part, ...$moreParts], fn($part) => $part !== '')); |
575 | 575 | } |
576 | | - |
577 | | - /** |
578 | | - * @throws InvariantViolation |
579 | | - * @return list<string> |
580 | | - */ |
581 | | - private function getPossibleTypes(Type $type) : array |
582 | | - { |
583 | | - if ($type instanceof NonNull) { |
584 | | - $type = $type->getWrappedType(); |
585 | | - } |
586 | | - |
587 | | - if ($type instanceof UnionType) { |
588 | | - $possible = []; |
589 | | - foreach ($type->getTypes() as $possibleType) { |
590 | | - $possible[] = $possibleType->name; |
591 | | - } |
592 | | - |
593 | | - return $possible; |
594 | | - } |
595 | | - |
596 | | - if ($type instanceof InterfaceType) { |
597 | | - $possible = []; |
598 | | - foreach ($this->schema->getImplementations($type)->objects() as $possibleType) { |
599 | | - $possible[] = $possibleType->name; |
600 | | - } |
601 | | - |
602 | | - return $possible; |
603 | | - } |
604 | | - |
605 | | - return []; |
606 | | - } |
607 | 576 | } |
0 commit comments