1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/******************************************************************************* |
4
|
|
|
* This file is part of the GraphQL Bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) YnloUltratech <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
******************************************************************************/ |
11
|
|
|
|
12
|
|
|
namespace Ynlo\GraphQLBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\FileLocator; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
17
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
18
|
|
|
use Ynlo\GraphQLBundle\Cache\DefinitionCacheWarmer; |
19
|
|
|
use Ynlo\GraphQLBundle\Controller\GraphQLEndpointController; |
20
|
|
|
use Ynlo\GraphQLBundle\Encoder\IDEncoderManager; |
21
|
|
|
use Ynlo\GraphQLBundle\GraphiQL\JWTGraphiQLAuthentication; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class YnloGraphQLExtension |
25
|
|
|
*/ |
26
|
|
|
class YnloGraphQLExtension extends Extension |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
1 |
|
public function load(array $configs, ContainerBuilder $container) |
32
|
|
|
{ |
33
|
1 |
|
$configuration = new Configuration(); |
34
|
1 |
|
$config = $this->processConfiguration($configuration, $configs); |
35
|
|
|
|
36
|
1 |
|
if (!isset($config['namespaces']['bundles']['aliases']['GraphQLBundle'])) { |
37
|
1 |
|
$config['namespaces']['bundles']['aliases']['GraphQLBundle'] = 'AppBundle'; |
38
|
|
|
} |
39
|
|
|
|
40
|
1 |
|
$container->setParameter('graphql.config', $config); |
41
|
1 |
|
$container->setParameter('graphql.pagination', $config['pagination'] ?? []); |
42
|
1 |
|
$container->setParameter('graphql.error_handling', $config['error_handling'] ?? []); |
43
|
1 |
|
$container->setParameter('graphql.error_handling.controlled_errors', $config['error_handling']['controlled_errors'] ?? []); |
44
|
1 |
|
$container->setParameter('graphql.namespaces', $config['namespaces'] ?? []); |
45
|
1 |
|
$container->setParameter('graphql.cors_config', $config['cors'] ?? []); |
46
|
1 |
|
$container->setParameter('graphql.graphiql', $config['graphiql'] ?? []); |
47
|
1 |
|
$container->setParameter('graphql.graphiql_auth_jwt', $config['graphiql']['authentication']['provider']['jwt'] ?? []); |
48
|
1 |
|
$container->setParameter('graphql.security.validation_rules', $config['security']['validation_rules'] ?? []); |
49
|
|
|
|
50
|
1 |
|
$endpointsConfig = []; |
51
|
1 |
|
$endpointsConfig['endpoints'] = $config['endpoints'] ?? []; |
52
|
1 |
|
$endpointsConfig['default'] = $config['endpoint_default'] ?? null; |
53
|
1 |
|
$endpointsConfig['alias'] = $config['endpoint_alias'] ?? []; |
54
|
|
|
|
55
|
1 |
|
$container->setParameter('graphql.endpoints', $endpointsConfig); |
56
|
1 |
|
$container->setParameter('graphql.endpoints_list', array_keys($endpointsConfig['endpoints'])); |
57
|
|
|
|
58
|
1 |
|
$graphiQLAuthProvider = null; |
59
|
1 |
|
if ($config['graphiql']['authentication']['provider']['jwt']['enabled'] ?? false) { |
60
|
1 |
|
$graphiQLAuthProvider = JWTGraphiQLAuthentication::class; |
61
|
|
|
} |
62
|
1 |
|
if ($config['graphiql']['authentication']['provider']['custom'] ?? false) { |
63
|
|
|
$graphiQLAuthProvider = $config['graphiql']['authentication']['provider']['custom']; |
64
|
|
|
} |
65
|
1 |
|
$container->setParameter('graphql.graphiql_auth_provider', $graphiQLAuthProvider); |
66
|
|
|
|
67
|
1 |
|
$configDir = __DIR__.'/../Resources/config'; |
68
|
1 |
|
$loader = new YamlFileLoader($container, new FileLocator($configDir)); |
69
|
1 |
|
$loader->load('services.yml'); |
70
|
|
|
|
71
|
1 |
|
if ($container->getParameter('kernel.environment') !== 'dev') { |
72
|
1 |
|
$container->getDefinition(DefinitionCacheWarmer::class)->clearTag('kernel.event_subscriber'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
//build the ID encoder manager with configured encoder |
76
|
1 |
|
$container->getDefinition(IDEncoderManager::class) |
77
|
1 |
|
->setPublic(true) |
78
|
1 |
|
->replaceArgument(0, $container->getDefinition($config['id_encoder'])); |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
//endpoint definition |
82
|
1 |
|
$container->getDefinition(GraphQLEndpointController::class) |
83
|
1 |
|
->addMethodCall('setErrorFormatter', [$container->getDefinition($config['error_handling']['formatter'])]) |
84
|
1 |
|
->addMethodCall('setErrorHandler', [$container->getDefinition($config['error_handling']['handler'])]); |
85
|
1 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritDoc} |
89
|
|
|
*/ |
90
|
1 |
|
public function getAlias() |
91
|
|
|
{ |
92
|
1 |
|
return 'graphql'; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|