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