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