vendor/overblog/graphql-bundle/src/Resolver/TypeResolver.php line 61

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Overblog\GraphQLBundle\Resolver;
  4. use GraphQL\Type\Definition\Type;
  5. use Overblog\GraphQLBundle\Event\Events;
  6. use Overblog\GraphQLBundle\Event\TypeLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  8. use function sprintf;
  9. class TypeResolver extends AbstractResolver
  10. {
  11.     private array $cache = [];
  12.     private ?string $currentSchemaName null;
  13.     private EventDispatcherInterface $dispatcher;
  14.     public function setDispatcher(EventDispatcherInterface $dispatcher): void
  15.     {
  16.         $this->dispatcher $dispatcher;
  17.     }
  18.     public function setCurrentSchemaName(?string $currentSchemaName): void
  19.     {
  20.         $this->currentSchemaName $currentSchemaName;
  21.     }
  22.     /**
  23.      * @param mixed $solution
  24.      */
  25.     protected function onLoadSolution($solution): void
  26.     {
  27.         if (isset($this->dispatcher)) {
  28.             // @phpstan-ignore-next-line (only for Symfony 4.4)
  29.             $this->dispatcher->dispatch(new TypeLoadedEvent($solution$this->currentSchemaName), Events::TYPE_LOADED);
  30.         }
  31.     }
  32.     /**
  33.      * @param string $alias
  34.      *
  35.      * @return Type
  36.      */
  37.     public function resolve($alias): ?Type
  38.     {
  39.         if (null === $alias) {
  40.             return null;
  41.         }
  42.         if (!isset($this->cache[$alias])) {
  43.             $type $this->baseType($alias);
  44.             $this->cache[$alias] = $type;
  45.         }
  46.         return $this->cache[$alias];
  47.     }
  48.     private function baseType(string $alias): Type
  49.     {
  50.         $type $this->getSolution($alias);
  51.         if (null === $type) {
  52.             throw new UnresolvableException(
  53.                 sprintf('Could not find type with alias "%s". Did you forget to define it?'$alias)
  54.             );
  55.         }
  56.         return $type;
  57.     }
  58.     protected function supportedSolutionClass(): ?string
  59.     {
  60.         return Type::class;
  61.     }
  62. }