|
27 | 27 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
28 | 28 | use Symfony\Component\DependencyInjection\Definition; |
29 | 29 | use Symfony\Component\DependencyInjection\Reference; |
| 30 | +use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
| 31 | +use Symfony\Component\HttpFoundation\Session\SessionInterface; |
| 32 | +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
| 33 | +use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; |
| 34 | +use Symfony\Component\Security\Core\User\UserProviderInterface; |
30 | 35 | use TheCodingMachine\CacheUtils\ClassBoundCache; |
31 | 36 | use TheCodingMachine\CacheUtils\ClassBoundCacheContract; |
32 | 37 | use TheCodingMachine\CacheUtils\ClassBoundCacheContractInterface; |
33 | 38 | use TheCodingMachine\CacheUtils\ClassBoundMemoryAdapter; |
34 | 39 | use TheCodingMachine\CacheUtils\FileBoundCache; |
35 | 40 | use TheCodingMachine\ClassExplorer\Glob\GlobClassExplorer; |
| 41 | +use TheCodingMachine\GraphQLite\AggregateControllerQueryProviderFactory; |
36 | 42 | use TheCodingMachine\GraphQLite\AnnotationReader; |
37 | 43 | use TheCodingMachine\GraphQLite\Annotations\AbstractRequest; |
38 | 44 | use TheCodingMachine\GraphQLite\Annotations\Autowire; |
39 | 45 | use TheCodingMachine\GraphQLite\Annotations\Field; |
40 | 46 | use TheCodingMachine\GraphQLite\Annotations\Mutation; |
41 | 47 | use TheCodingMachine\GraphQLite\Annotations\Parameter; |
42 | 48 | use TheCodingMachine\GraphQLite\Annotations\Query; |
| 49 | +use TheCodingMachine\Graphqlite\Bundle\Controller\GraphQL\LoginController; |
43 | 50 | use TheCodingMachine\GraphQLite\FieldsBuilder; |
44 | 51 | use TheCodingMachine\GraphQLite\FieldsBuilderFactory; |
45 | 52 | use TheCodingMachine\GraphQLite\GraphQLException; |
@@ -80,24 +87,54 @@ public function process(ContainerBuilder $container) |
80 | 87 | $typesNamespaces = $container->getParameter('graphqlite.namespace.types'); |
81 | 88 |
|
82 | 89 | // 2 seconds of TTL in environment mode. Otherwise, let's cache forever! |
| 90 | + |
| 91 | + $schemaFactory = $container->getDefinition(SchemaFactory::class); |
| 92 | + |
83 | 93 | $env = $container->getParameter('kernel.environment'); |
84 | | - $globTtl = null; |
85 | | - if ($env === 'dev') { |
86 | | - $globTtl = 2; |
| 94 | + if ($env === 'prod') { |
| 95 | + $schemaFactory->addMethodCall('prodMode'); |
| 96 | + } elseif ($env === 'dev') { |
| 97 | + $schemaFactory->addMethodCall('devMode'); |
| 98 | + } |
| 99 | + |
| 100 | + $disableLogin = false; |
| 101 | + if ($container->getParameter('graphqlite.security.enable_login') === 'auto' |
| 102 | + && (!$container->has(UserProviderInterface::class) || |
| 103 | + !$container->has(UserPasswordEncoderInterface::class) || |
| 104 | + !$container->has(TokenStorageInterface::class) || |
| 105 | + !$container->has(SessionInterface::class) |
| 106 | + )) { |
| 107 | + $disableLogin = true; |
| 108 | + } |
| 109 | + if ($container->getParameter('graphqlite.security.enable_login') === 'off') { |
| 110 | + $disableLogin = true; |
| 111 | + } |
| 112 | + // If the security is disabled, let's remove the LoginController |
| 113 | + if ($disableLogin === true) { |
| 114 | + $container->removeDefinition(LoginController::class); |
| 115 | + $container->removeDefinition(AggregateControllerQueryProviderFactory::class); |
| 116 | + } |
| 117 | + |
| 118 | + if ($container->getParameter('graphqlite.security.enable_login') === 'on') { |
| 119 | + if (!$container->has(SessionInterface::class)) { |
| 120 | + throw new GraphQLException('In order to enable the login/logout mutations (via the graphqlite.security.enable_login parameter), you need to enable session support (via the "framework.session.enabled" config parameter).'); |
| 121 | + } |
| 122 | + if (!$container->has(UserPasswordEncoderInterface::class) || !$container->has(TokenStorageInterface::class) || !$container->has(UserProviderInterface::class)) { |
| 123 | + throw new GraphQLException('In order to enable the login/logout mutations (via the graphqlite.security.enable_login parameter), you need to install the security bundle. Please be sure to correctly configure the user provider (in the security.providers configuration settings)'); |
| 124 | + } |
87 | 125 | } |
88 | 126 |
|
89 | | - $schemaFactory = $container->getDefinition(SchemaFactory::class); |
90 | 127 |
|
91 | 128 | foreach ($container->getDefinitions() as $id => $definition) { |
92 | 129 | if ($definition->isAbstract() || $definition->getClass() === null) { |
93 | 130 | continue; |
94 | 131 | } |
95 | 132 | $class = $definition->getClass(); |
96 | | - foreach ($controllersNamespaces as $controllersNamespace) { |
| 133 | +/* foreach ($controllersNamespaces as $controllersNamespace) { |
97 | 134 | if (strpos($class, $controllersNamespace) === 0) { |
98 | 135 | $definition->addTag('graphql.annotated.controller'); |
99 | 136 | } |
100 | | - } |
| 137 | + }*/ |
101 | 138 |
|
102 | 139 | foreach ($typesNamespaces as $typesNamespace) { |
103 | 140 | if (strpos($class, $typesNamespace) === 0) { |
@@ -165,10 +202,12 @@ public function process(ContainerBuilder $container) |
165 | 202 |
|
166 | 203 | // Register graphql.queryprovider |
167 | 204 | $this->mapAdderToTag('graphql.queryprovider', 'addQueryProvider', $container, $schemaFactory); |
| 205 | + $this->mapAdderToTag('graphql.queryprovider_factory', 'addQueryProviderFactory', $container, $schemaFactory); |
168 | 206 | $this->mapAdderToTag('graphql.root_type_mapper', 'addRootTypeMapper', $container, $schemaFactory); |
169 | 207 | $this->mapAdderToTag('graphql.parameter_mapper', 'addParameterMapper', $container, $schemaFactory); |
170 | 208 | $this->mapAdderToTag('graphql.field_middleware', 'addFieldMiddleware', $container, $schemaFactory); |
171 | 209 | $this->mapAdderToTag('graphql.type_mapper', 'addTypeMapper', $container, $schemaFactory); |
| 210 | + $this->mapAdderToTag('graphql.type_mapper_factory', 'addTypeMapperFactory', $container, $schemaFactory); |
172 | 211 | } |
173 | 212 |
|
174 | 213 | /** |
|
0 commit comments