|
47 | 47 | use TheCodingMachine\GraphQLite\Security\FailAuthorizationService; |
48 | 48 | use TheCodingMachine\GraphQLite\Security\SecurityExpressionLanguageProvider; |
49 | 49 | use TheCodingMachine\GraphQLite\Types\ArgumentResolver; |
| 50 | +use TheCodingMachine\GraphQLite\Types\InputTypeValidatorInterface; |
50 | 51 | use TheCodingMachine\GraphQLite\Types\TypeResolver; |
51 | 52 | use TheCodingMachine\GraphQLite\Utils\NamespacedCache; |
52 | 53 | use TheCodingMachine\GraphQLite\Utils\Namespaces\NamespaceFactory; |
|
63 | 64 | */ |
64 | 65 | class SchemaFactory |
65 | 66 | { |
| 67 | + |
66 | 68 | public const GLOB_CACHE_SECONDS = 2; |
67 | 69 |
|
| 70 | + |
68 | 71 | /** @var string[] */ |
69 | | - private $controllerNamespaces = []; |
| 72 | + private array $controllerNamespaces = []; |
| 73 | + |
70 | 74 | /** @var string[] */ |
71 | | - private $typeNamespaces = []; |
| 75 | + private array $typeNamespaces = []; |
| 76 | + |
72 | 77 | /** @var QueryProviderInterface[] */ |
73 | | - private $queryProviders = []; |
| 78 | + private array $queryProviders = []; |
| 79 | + |
74 | 80 | /** @var QueryProviderFactoryInterface[] */ |
75 | | - private $queryProviderFactories = []; |
| 81 | + private array $queryProviderFactories = []; |
| 82 | + |
76 | 83 | /** @var RootTypeMapperFactoryInterface[] */ |
77 | | - private $rootTypeMapperFactories = []; |
| 84 | + private array $rootTypeMapperFactories = []; |
| 85 | + |
78 | 86 | /** @var TypeMapperInterface[] */ |
79 | | - private $typeMappers = []; |
| 87 | + private array $typeMappers = []; |
| 88 | + |
80 | 89 | /** @var TypeMapperFactoryInterface[] */ |
81 | | - private $typeMapperFactories = []; |
| 90 | + private array $typeMapperFactories = []; |
| 91 | + |
82 | 92 | /** @var ParameterMiddlewareInterface[] */ |
83 | | - private $parameterMiddlewares = []; |
84 | | - /** @var Reader */ |
85 | | - private $doctrineAnnotationReader; |
86 | | - /** @var AuthenticationServiceInterface|null */ |
87 | | - private $authenticationService; |
88 | | - /** @var AuthorizationServiceInterface|null */ |
89 | | - private $authorizationService; |
90 | | - /** @var CacheInterface */ |
91 | | - private $cache; |
92 | | - /** @var NamingStrategyInterface|null */ |
93 | | - private $namingStrategy; |
94 | | - /** @var ContainerInterface */ |
95 | | - private $container; |
96 | | - /** @var ClassNameMapper */ |
97 | | - private $classNameMapper; |
98 | | - /** @var SchemaConfig */ |
99 | | - private $schemaConfig; |
100 | | - /** @var int|null */ |
101 | | - private $globTTL = self::GLOB_CACHE_SECONDS; |
| 93 | + private array $parameterMiddlewares = []; |
| 94 | + |
| 95 | + private ?Reader $doctrineAnnotationReader = null; |
| 96 | + |
| 97 | + private ?AuthenticationServiceInterface $authenticationService = null; |
| 98 | + |
| 99 | + private ?AuthorizationServiceInterface $authorizationService = null; |
| 100 | + |
| 101 | + private ?InputTypeValidatorInterface $inputTypeValidator = null; |
| 102 | + |
| 103 | + private CacheInterface $cache; |
| 104 | + |
| 105 | + private ?NamingStrategyInterface $namingStrategy = null; |
| 106 | + |
| 107 | + private ContainerInterface $container; |
| 108 | + |
| 109 | + private ?ClassNameMapper $classNameMapper = null; |
| 110 | + |
| 111 | + private ?SchemaConfig $schemaConfig = null; |
| 112 | + |
| 113 | + private ?int $globTTL = self::GLOB_CACHE_SECONDS; |
| 114 | + |
102 | 115 | /** @var array<int, FieldMiddlewareInterface> */ |
103 | | - private $fieldMiddlewares = []; |
104 | | - /** @var ExpressionLanguage|null */ |
105 | | - private $expressionLanguage; |
106 | | - /** @var string */ |
107 | | - private $cacheNamespace; |
| 116 | + private array $fieldMiddlewares = []; |
| 117 | + |
| 118 | + private ?ExpressionLanguage $expressionLanguage = null; |
| 119 | + |
| 120 | + private string $cacheNamespace; |
| 121 | + |
108 | 122 |
|
109 | 123 | public function __construct(CacheInterface $cache, ContainerInterface $container) |
110 | 124 | { |
@@ -229,6 +243,14 @@ public function setAuthorizationService(AuthorizationServiceInterface $authoriza |
229 | 243 | return $this; |
230 | 244 | } |
231 | 245 |
|
| 246 | + public function setInputTypeValidator(?InputTypeValidatorInterface $inputTypeValidator): self |
| 247 | + { |
| 248 | + $this->inputTypeValidator = $inputTypeValidator; |
| 249 | + |
| 250 | + return $this; |
| 251 | + } |
| 252 | + |
| 253 | + |
232 | 254 | public function setNamingStrategy(NamingStrategyInterface $namingStrategy): self |
233 | 255 | { |
234 | 256 | $this->namingStrategy = $namingStrategy; |
@@ -305,20 +327,21 @@ public function setExpressionLanguage(ExpressionLanguage $expressionLanguage): s |
305 | 327 |
|
306 | 328 | public function createSchema(): Schema |
307 | 329 | { |
308 | | - $symfonyCache = new Psr16Adapter($this->cache, $this->cacheNamespace); |
309 | | - $annotationReader = new AnnotationReader($this->getDoctrineAnnotationReader($symfonyCache), AnnotationReader::LAX_MODE); |
310 | | - $authenticationService = $this->authenticationService ?: new FailAuthenticationService(); |
311 | | - $authorizationService = $this->authorizationService ?: new FailAuthorizationService(); |
312 | | - $typeResolver = new TypeResolver(); |
313 | | - $namespacedCache = new NamespacedCache($this->cache); |
314 | | - $cachedDocBlockFactory = new CachedDocBlockFactory($namespacedCache); |
315 | | - $namingStrategy = $this->namingStrategy ?: new NamingStrategy(); |
316 | | - $typeRegistry = new TypeRegistry(); |
| 330 | + $symfonyCache = new Psr16Adapter($this->cache, $this->cacheNamespace); |
| 331 | + $annotationReader = new AnnotationReader($this->getDoctrineAnnotationReader($symfonyCache), AnnotationReader::LAX_MODE); |
| 332 | + $authenticationService = $this->authenticationService ?: new FailAuthenticationService(); |
| 333 | + $authorizationService = $this->authorizationService ?: new FailAuthorizationService(); |
| 334 | + $typeResolver = new TypeResolver(); |
| 335 | + $namespacedCache = new NamespacedCache($this->cache); |
| 336 | + $cachedDocBlockFactory = new CachedDocBlockFactory($namespacedCache); |
| 337 | + $namingStrategy = $this->namingStrategy ?: new NamingStrategy(); |
| 338 | + $typeRegistry = new TypeRegistry(); |
317 | 339 |
|
318 | 340 | $namespaceFactory = new NamespaceFactory($namespacedCache, $this->classNameMapper, $this->globTTL); |
319 | | - $nsList = array_map(static function (string $namespace) use ($namespaceFactory) { |
320 | | - return $namespaceFactory->createNamespace($namespace); |
321 | | - }, $this->typeNamespaces); |
| 341 | + $nsList = array_map( |
| 342 | + static fn (string $namespace) => $namespaceFactory->createNamespace($namespace), |
| 343 | + $this->typeNamespaces |
| 344 | + ); |
322 | 345 |
|
323 | 346 | $expressionLanguage = $this->expressionLanguage ?: new ExpressionLanguage($symfonyCache); |
324 | 347 | $expressionLanguage->registerProvider(new SecurityExpressionLanguageProvider()); |
@@ -389,7 +412,7 @@ public function createSchema(): Schema |
389 | 412 |
|
390 | 413 | $typeGenerator = new TypeGenerator($annotationReader, $namingStrategy, $typeRegistry, $this->container, $recursiveTypeMapper, $fieldsBuilder); |
391 | 414 | $inputTypeUtils = new InputTypeUtils($annotationReader, $namingStrategy); |
392 | | - $inputTypeGenerator = new InputTypeGenerator($inputTypeUtils, $fieldsBuilder); |
| 415 | + $inputTypeGenerator = new InputTypeGenerator($inputTypeUtils, $fieldsBuilder, $this->inputTypeValidator); |
393 | 416 |
|
394 | 417 | foreach ($nsList as $ns) { |
395 | 418 | $compositeTypeMapper->addTypeMapper(new GlobTypeMapper( |
@@ -418,6 +441,7 @@ public function createSchema(): Schema |
418 | 441 | $recursiveTypeMapper, |
419 | 442 | $this->container, |
420 | 443 | $namespacedCache, |
| 444 | + $this->inputTypeValidator, |
421 | 445 | $this->globTTL |
422 | 446 | ); |
423 | 447 | } |
|
0 commit comments