vendor/overblog/graphql-bundle/src/Definition/Type/ExtensibleSchema.php line 51

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Overblog\GraphQLBundle\Definition\Type;
  4. use GraphQL\Type\Definition\Type;
  5. use GraphQL\Type\Schema;
  6. use GraphQL\Type\SchemaConfig;
  7. use Overblog\GraphQLBundle\Definition\Type\SchemaExtension\SchemaExtensionInterface;
  8. use Overblog\GraphQLBundle\Resolver\UnresolvableException;
  9. class ExtensibleSchema extends Schema
  10. {
  11.     public function __construct($config)
  12.     {
  13.         parent::__construct($this->addDefaultFallBackToTypeLoader(
  14.             $config instanceof SchemaConfig $config SchemaConfig::create($config)
  15.         ));
  16.     }
  17.     /** @var SchemaExtensionInterface[] */
  18.     private array $extensions = [];
  19.     /**
  20.      * @param SchemaExtensionInterface[] $extensions
  21.      *
  22.      * @return $this
  23.      */
  24.     public function setExtensions(array $extensions)
  25.     {
  26.         $this->extensions = [];
  27.         foreach ($extensions as $extension) {
  28.             $this->addExtension($extension);
  29.         }
  30.         return $this;
  31.     }
  32.     public function addExtension(SchemaExtensionInterface $extension): void
  33.     {
  34.         $this->extensions[] = $extension;
  35.     }
  36.     /**
  37.      * @return $this
  38.      */
  39.     public function processExtensions()
  40.     {
  41.         foreach ($this->extensions as $extension) {
  42.             $extension->process($this);
  43.         }
  44.         return $this;
  45.     }
  46.     private function addDefaultFallBackToTypeLoader(SchemaConfig $schemaConfig): SchemaConfig
  47.     {
  48.         $typeLoader $schemaConfig->typeLoader;
  49.         $loaderWrapper null;
  50.         $loaderWrapper = function ($name) use ($typeLoader, &$schemaConfig, &$loaderWrapper): ?Type {
  51.             $type null;
  52.             try {
  53.                 $type $typeLoader($name);
  54.             } catch (UnresolvableException $e) {
  55.                 // second chance for types with un-registered name in TypeResolver
  56.                 // we disabled the custom typeLoader to force default loader usage
  57.                 $schemaConfig->typeLoader null;
  58.                 $type $this->getType($name);
  59.                 $schemaConfig->typeLoader $loaderWrapper// @phpstan-ignore-line
  60.             }
  61.             return $type;
  62.         };
  63.         $schemaConfig->typeLoader $loaderWrapper// @phpstan-ignore-line
  64.         return $schemaConfig;
  65.     }
  66. }