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\Definition\Builder\NodeBuilder; |
15
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
16
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Configuration |
20
|
|
|
*/ |
21
|
|
|
class Configuration implements ConfigurationInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
public function getConfigTreeBuilder() |
27
|
|
|
{ |
28
|
|
|
$treeBuilder = new TreeBuilder(); |
29
|
|
|
/** @var NodeBuilder $rootNode */ |
30
|
|
|
$rootNode = $treeBuilder->root('graphql')->addDefaultsIfNotSet()->children(); |
|
|
|
|
31
|
|
|
$this->configureCORS($rootNode); |
32
|
|
|
$this->configureGraphiQL($rootNode); |
33
|
|
|
$this->configureDefinition($rootNode); |
34
|
|
|
|
35
|
|
|
return $treeBuilder; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
protected function configureGraphiQL(NodeBuilder $root) |
39
|
|
|
{ |
40
|
|
|
$graphiql = $root->arrayNode('graphiql')->addDefaultsIfNotSet()->children(); |
41
|
|
|
|
42
|
|
|
$graphiql->scalarNode('title') |
43
|
|
|
->defaultValue('GraphQL API Explorer'); |
44
|
|
|
|
45
|
|
|
$graphiql |
46
|
|
|
->scalarNode('data_warning_message') |
47
|
|
|
->defaultValue('Heads up! GraphQL Explorer makes use of your <strong>real</strong>, <strong>live</strong>, <strong>production</strong> data.'); |
48
|
|
|
$graphiql->booleanNode('data_warning_dismissible')->defaultTrue(); |
49
|
|
|
$graphiql->enumNode('data_warning_style')->values(['info', 'warning', 'danger'])->defaultValue('danger'); |
50
|
|
|
|
51
|
|
|
$graphiql->scalarNode('template') |
52
|
|
|
->defaultValue('@YnloGraphQL/explorer.twig'); |
53
|
|
|
|
54
|
|
|
$authentication = $graphiql->arrayNode('authentication')->addDefaultsIfNotSet()->children(); |
55
|
|
|
$authentication |
56
|
|
|
->booleanNode('required') |
57
|
|
|
->info( |
58
|
|
|
'The API require credentials to make any requests, |
59
|
|
|
if this value is FALSE and a provider is specified the authentication is optional.' |
60
|
|
|
) |
61
|
|
|
->defaultFalse(); |
62
|
|
|
|
63
|
|
|
$authentication->scalarNode('login_message') |
64
|
|
|
->defaultValue('Start exploring GraphQL API queries using your account’s data now.'); |
65
|
|
|
|
66
|
|
|
$authenticationProvider = $authentication->arrayNode('provider')->children(); |
67
|
|
|
|
68
|
|
|
$jwt = $authenticationProvider->arrayNode('jwt')->canBeEnabled()->children(); |
69
|
|
|
|
70
|
|
|
$jwtLogin = $jwt->arrayNode('login')->children(); |
71
|
|
|
|
72
|
|
|
$jwtLogin->scalarNode('url') |
73
|
|
|
->info('Route name or URI to make the login process to retrieve the token.') |
74
|
|
|
->isRequired(); |
75
|
|
|
|
76
|
|
|
$jwtLogin->scalarNode('username_parameter') |
77
|
|
|
->defaultValue('username'); |
78
|
|
|
|
79
|
|
|
$jwtLogin->scalarNode('password_parameter') |
80
|
|
|
->defaultValue('password'); |
81
|
|
|
|
82
|
|
|
$jwtLogin->enumNode('parameters_in') |
83
|
|
|
->values(['form', 'query', 'header']) |
84
|
|
|
->info('How pass parameters to request the token') |
85
|
|
|
->defaultValue('form'); |
86
|
|
|
|
87
|
|
|
$jwtLogin->scalarNode('response_token_path') |
88
|
|
|
->defaultValue('token') |
89
|
|
|
->info('Where the token should be located in the response in case of JSON, set null if the response is the token.'); |
90
|
|
|
|
91
|
|
|
$jwtRequests = $jwt->arrayNode('requests')->addDefaultsIfNotSet()->children(); |
92
|
|
|
|
93
|
|
|
$jwtRequests->enumNode('token_in') |
94
|
|
|
->values(['query', 'header']) |
95
|
|
|
->info('Where should be located the token on every request') |
96
|
|
|
->defaultValue('header'); |
97
|
|
|
|
98
|
|
|
$jwtRequests->scalarNode('token_name') |
99
|
|
|
->defaultValue('Authorization') |
100
|
|
|
->info('Name of the token in query or header name'); |
101
|
|
|
|
102
|
|
|
$jwtRequests->scalarNode('token_template') |
103
|
|
|
->defaultValue('Bearer {token}') |
104
|
|
|
->info('Customize how the token should be send, use the place holder {token} to replace for current token'); |
105
|
|
|
|
106
|
|
|
$authenticationProvider->scalarNode('custom') |
107
|
|
|
->defaultNull() |
108
|
|
|
->info('Configure custom service to use as authentication provider'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
protected function configureCORS(NodeBuilder $root) |
112
|
|
|
{ |
113
|
|
|
$cors = $root->arrayNode('cors')->canBeEnabled()->children(); |
114
|
|
|
$cors->booleanNode('allow_credentials')->defaultTrue(); |
115
|
|
|
$cors->variableNode('allow_headers')->defaultValue(['Origin', 'Content-Type', 'Accept', 'Authorization']); |
116
|
|
|
$cors->integerNode('max_age')->defaultValue(3600); |
117
|
|
|
$cors->variableNode('allow_methods')->defaultValue(['POST', 'GET', 'OPTIONS']); |
118
|
|
|
$cors->variableNode('allow_origins')->defaultValue(['*']); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
protected function configureDefinition(NodeBuilder $root) |
122
|
|
|
{ |
123
|
|
|
$definitions = $root->arrayNode('definitions')->addDefaultsIfNotSet()->children(); |
124
|
|
|
|
125
|
|
|
$extensions = $definitions->arrayNode('extensions')->addDefaultsIfNotSet(); |
126
|
|
|
$this->configureExtensionPagination($extensions->children()); |
127
|
|
|
$this->configureExtensionNamespace($extensions->children()); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
protected function configureExtensionPagination(NodeBuilder $root) |
131
|
|
|
{ |
132
|
|
|
$pagination = $root->arrayNode('pagination')->addDefaultsIfNotSet()->children(); |
133
|
|
|
$pagination->integerNode('limit') |
134
|
|
|
->defaultValue(100)->info('Maximum limit allowed for all paginations'); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
protected function configureExtensionNamespace(NodeBuilder $root) |
138
|
|
|
{ |
139
|
|
|
$namespaces = $root->arrayNode('namespaces') |
140
|
|
|
->info( |
141
|
|
|
'Group GraphQL schema using namespaced schemas. |
142
|
|
|
On large schemas is helpful to keep schemas grouped by bundle and node' |
143
|
|
|
) |
144
|
|
|
->canBeEnabled() |
145
|
|
|
->addDefaultsIfNotSet() |
146
|
|
|
->children(); |
147
|
|
|
|
148
|
|
|
$bundles = $namespaces->arrayNode('bundles') |
149
|
|
|
->info('Group each bundle into a separate schema definition') |
150
|
|
|
->canBeDisabled() |
151
|
|
|
->addDefaultsIfNotSet() |
152
|
|
|
->children(); |
153
|
|
|
|
154
|
|
|
$bundles->scalarNode('suffix') |
155
|
|
|
->info('The following suffix will be used for bundle groups') |
156
|
|
|
->defaultValue('Bundle'); |
157
|
|
|
|
158
|
|
|
$bundles->variableNode('ignore') |
159
|
|
|
->info('The following bundles will be ignore for grouping, all definitions will be placed in the root query or mutation') |
160
|
|
|
->defaultValue(['AppBundle']); |
161
|
|
|
|
162
|
|
|
$bundles->arrayNode('aliases') |
163
|
|
|
->info( |
164
|
|
|
'Define aliases for bundles to set definitions inside other desired bundle name. |
165
|
|
|
Can be used to group multiple bundles or publish a bundle with a different name' |
166
|
|
|
) |
167
|
|
|
->example('SecurityBundle: AppBundle') |
168
|
|
|
->useAttributeAsKey('name') |
169
|
|
|
->prototype('scalar'); |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
$nodes = $namespaces->arrayNode('nodes') |
173
|
|
|
->info('Group queries and mutations of the same node into a node specific schema definition.') |
174
|
|
|
->addDefaultsIfNotSet() |
175
|
|
|
->canBeDisabled() |
176
|
|
|
->children(); |
177
|
|
|
|
178
|
|
|
$nodes->scalarNode('query_suffix') |
179
|
|
|
->info('The following suffix will be used to create the name for queries to the same node') |
180
|
|
|
->defaultValue('Query'); |
181
|
|
|
|
182
|
|
|
$nodes->scalarNode('mutation_suffix') |
183
|
|
|
->info('The following suffix will be used to create the name for mutations to the same node') |
184
|
|
|
->defaultValue('Mutation'); |
185
|
|
|
|
186
|
|
|
$nodes->variableNode('ignore') |
187
|
|
|
->info('The following nodes will be ignore for grouping, all definitions will be placed in the root query or mutation') |
188
|
|
|
->defaultValue(['Node']); |
189
|
|
|
|
190
|
|
|
$nodes->arrayNode('aliases') |
191
|
|
|
->info( |
192
|
|
|
'Define aliases for nodes to set definitions inside other desired node name. |
193
|
|
|
Can be used to group multiple nodes or publish a node with a different group name' |
194
|
|
|
) |
195
|
|
|
->example('InvoiceItem: Invoice') |
196
|
|
|
->useAttributeAsKey('name') |
197
|
|
|
->prototype('scalar'); |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|