1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Overblog\GraphQLBundle\Config; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
6
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
7
|
|
|
|
8
|
|
|
abstract class TypeWithOutputFieldsDefinition extends TypeDefinition |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @param string $name |
12
|
|
|
* |
13
|
|
|
* @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition |
14
|
|
|
*/ |
15
|
29 |
|
protected function outputFieldsSelection($name) |
16
|
|
|
{ |
17
|
29 |
|
$builder = new TreeBuilder(); |
18
|
29 |
|
$node = $builder->root($name); |
19
|
|
|
$node |
20
|
29 |
|
->isRequired() |
21
|
29 |
|
->requiresAtLeastOneElement(); |
22
|
|
|
|
23
|
|
|
/* @var ArrayNodeDefinition $prototype */ |
24
|
29 |
|
$prototype = $node->useAttributeAsKey('name', false)->prototype('array'); |
25
|
|
|
|
26
|
|
|
$prototype |
27
|
29 |
|
->children() |
28
|
29 |
|
->append($this->typeSelection()) |
29
|
29 |
|
->arrayNode('args') |
30
|
29 |
|
->info('Array of possible type arguments. Each entry is expected to be an array with following keys: name (string), type') |
31
|
29 |
|
->useAttributeAsKey('name', false) |
32
|
29 |
|
->prototype('array') |
33
|
|
|
// Allow arg type short syntax (Arg: Type => Arg: {type: Type}) |
34
|
29 |
|
->beforeNormalization() |
35
|
29 |
|
->ifTrue(function ($options) { |
36
|
17 |
|
return is_string($options); |
37
|
29 |
|
}) |
38
|
29 |
|
->then(function ($options) { |
39
|
1 |
|
return ['type' => $options]; |
40
|
29 |
|
}) |
41
|
29 |
|
->end() |
42
|
29 |
|
->children() |
43
|
29 |
|
->append($this->typeSelection(true)) |
44
|
29 |
|
->append($this->descriptionSection()) |
45
|
29 |
|
->append($this->defaultValueSection()) |
46
|
29 |
|
->end() |
47
|
29 |
|
->end() |
48
|
29 |
|
->end() |
49
|
29 |
|
->variableNode('resolve') |
50
|
29 |
|
->info('Value resolver (expression language can be use here)') |
51
|
29 |
|
->end() |
52
|
29 |
|
->append($this->descriptionSection()) |
53
|
29 |
|
->append($this->deprecationReasonSelection()) |
54
|
29 |
|
->variableNode('access') |
55
|
29 |
|
->info('Access control to field (expression language can be use here)') |
56
|
29 |
|
->end() |
57
|
29 |
|
->variableNode('public') |
58
|
29 |
|
->info('Visibility control to field (expression language can be use here)') |
59
|
29 |
|
->end() |
60
|
29 |
|
->variableNode('complexity') |
61
|
29 |
|
->info('Custom complexity calculator.') |
62
|
29 |
|
->end() |
63
|
29 |
|
->end(); |
64
|
|
|
|
65
|
29 |
|
return $node; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|