|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter; |
|
4
|
|
|
|
|
5
|
|
|
use GraphQL\Language\AST\Node; |
|
6
|
|
|
use GraphQL\Language\AST\NodeKind; |
|
7
|
|
|
use GraphQL\Language\AST\ValueNode; |
|
8
|
|
|
|
|
9
|
|
|
class FieldsNode implements NodeInterface |
|
10
|
|
|
{ |
|
11
|
|
|
public static function toConfig(Node $node, $property = 'fields') |
|
12
|
2 |
|
{ |
|
13
|
|
|
$config = []; |
|
14
|
2 |
|
if (!empty($node->$property)) { |
|
15
|
2 |
|
foreach ($node->$property as $definition) { |
|
16
|
2 |
|
$fieldConfig = [ |
|
17
|
2 |
|
'type' => TypeNode::toConfig($definition), |
|
18
|
|
|
'description' => DescriptionNode::toConfig($definition), |
|
19
|
2 |
|
]; |
|
20
|
2 |
|
|
|
21
|
|
|
if (!empty($definition->arguments)) { |
|
22
|
|
|
$fieldConfig['args'] = self::toConfig($definition, 'arguments'); |
|
23
|
2 |
|
} |
|
24
|
1 |
|
|
|
25
|
|
|
if (!empty($definition->defaultValue)) { |
|
26
|
|
|
$fieldConfig['defaultValue'] = self::astValueNodeToConfig($definition->defaultValue); |
|
27
|
2 |
|
} |
|
28
|
2 |
|
|
|
29
|
1 |
|
$directiveConfig = DirectiveNode::toConfig($definition); |
|
30
|
|
|
if (isset($directiveConfig['deprecationReason'])) { |
|
31
|
|
|
$fieldConfig['deprecationReason'] = $directiveConfig['deprecationReason']; |
|
32
|
2 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
$config[$definition->name->value] = $fieldConfig; |
|
35
|
|
|
} |
|
36
|
2 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
return $config; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
private static function astValueNodeToConfig(ValueNode $valueNode) |
|
42
|
|
|
{ |
|
43
|
|
|
$config = null; |
|
44
|
|
|
switch ($valueNode->kind) { |
|
|
|
|
|
|
45
|
|
|
case NodeKind::INT: |
|
46
|
|
|
$config = \intval($valueNode->value, 10); |
|
|
|
|
|
|
47
|
|
|
break; |
|
48
|
|
|
|
|
49
|
|
|
case NodeKind::FLOAT: |
|
50
|
|
|
$config = \floatval($valueNode->value); |
|
|
|
|
|
|
51
|
|
|
break; |
|
52
|
|
|
|
|
53
|
|
|
case NodeKind::STRING: |
|
54
|
|
|
case NodeKind::BOOLEAN: |
|
55
|
|
|
case NodeKind::ENUM: |
|
56
|
|
|
$config = $valueNode->value; |
|
|
|
|
|
|
57
|
|
|
break; |
|
58
|
|
|
|
|
59
|
|
|
case NodeKind::LST: |
|
60
|
|
|
$config = []; |
|
61
|
|
|
foreach ($valueNode->values as $node) { |
|
|
|
|
|
|
62
|
|
|
$config[] = self::astValueNodeToConfig($node); |
|
63
|
|
|
} |
|
64
|
|
|
break; |
|
65
|
|
|
|
|
66
|
|
|
case NodeKind::NULL: |
|
67
|
|
|
$config = null; |
|
68
|
|
|
break; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $config; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: