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