|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Overblog\GraphQLBundle\Config; |
|
6
|
|
|
|
|
7
|
|
|
use Overblog\GraphQLBundle\DependencyInjection\Configuration; |
|
8
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
9
|
|
|
|
|
10
|
|
|
abstract class TypeDefinition |
|
11
|
|
|
{ |
|
12
|
|
|
abstract public function getDefinition(); |
|
13
|
|
|
|
|
14
|
37 |
|
protected function __construct() |
|
15
|
|
|
{ |
|
16
|
37 |
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @return static |
|
20
|
|
|
*/ |
|
21
|
37 |
|
public static function create() |
|
22
|
|
|
{ |
|
23
|
37 |
|
return new static(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
37 |
|
protected function resolveTypeSection() |
|
27
|
|
|
{ |
|
28
|
37 |
|
$node = self::createNode('resolveType', 'variable'); |
|
29
|
|
|
|
|
30
|
37 |
|
return $node; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
37 |
|
protected function nameSection() |
|
34
|
|
|
{ |
|
35
|
37 |
|
$node = self::createNode('name', 'scalar'); |
|
36
|
37 |
|
$node->isRequired(); |
|
37
|
37 |
|
$node->validate() |
|
38
|
|
|
->ifTrue(function ($name) { |
|
39
|
32 |
|
return !\preg_match('/^[_a-z][_0-9a-z]*$/i', $name); |
|
40
|
37 |
|
}) |
|
41
|
37 |
|
->thenInvalid('Invalid type name "%s". (see https://facebook.github.io/graphql/October2016/#Name)') |
|
42
|
37 |
|
->end(); |
|
43
|
|
|
|
|
44
|
37 |
|
return $node; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
37 |
|
protected function defaultValueSection() |
|
48
|
|
|
{ |
|
49
|
37 |
|
$node = self::createNode('defaultValue', 'variable'); |
|
50
|
|
|
|
|
51
|
37 |
|
return $node; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
37 |
|
protected function descriptionSection() |
|
55
|
|
|
{ |
|
56
|
37 |
|
$node = self::createNode('description', 'scalar'); |
|
57
|
|
|
|
|
58
|
37 |
|
return $node; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
37 |
|
protected function deprecationReasonSelection() |
|
62
|
|
|
{ |
|
63
|
37 |
|
$node = self::createNode('deprecationReason', 'scalar'); |
|
64
|
|
|
|
|
65
|
37 |
|
$node->info('Text describing why this field is deprecated. When not empty - field will not be returned by introspection queries (unless forced)'); |
|
66
|
|
|
|
|
67
|
37 |
|
return $node; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
37 |
|
protected function typeSelection($isRequired = false) |
|
71
|
|
|
{ |
|
72
|
37 |
|
$node = self::createNode('type', 'scalar'); |
|
73
|
|
|
|
|
74
|
37 |
|
$node->info('One of internal or custom types.'); |
|
75
|
|
|
|
|
76
|
37 |
|
if ($isRequired) { |
|
77
|
37 |
|
$node->isRequired(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
37 |
|
return $node; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @internal |
|
85
|
|
|
* |
|
86
|
|
|
* @param string $name |
|
87
|
|
|
* @param string $type |
|
88
|
|
|
* |
|
89
|
|
|
* @return \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition |
|
90
|
|
|
*/ |
|
91
|
37 |
|
protected static function createNode(string $name, string $type = 'array') |
|
92
|
|
|
{ |
|
93
|
37 |
|
return Configuration::getRootNodeWithoutDeprecation(new TreeBuilder($name, $type), $name, $type); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|