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
|
2 |
|
public static function toConfig(Node $node, $property = 'fields') |
12
|
|
|
{ |
13
|
2 |
|
$config = []; |
14
|
2 |
|
if (!empty($node->$property)) { |
15
|
2 |
|
foreach ($node->$property as $definition) { |
16
|
|
|
$fieldConfig = [ |
17
|
2 |
|
'type' => TypeNode::toConfig($definition), |
18
|
2 |
|
'description' => DescriptionNode::toConfig($definition), |
19
|
|
|
]; |
20
|
|
|
|
21
|
2 |
|
if (!empty($definition->arguments)) { |
22
|
2 |
|
$fieldConfig['args'] = self::toConfig($definition, 'arguments'); |
23
|
|
|
} |
24
|
|
|
|
25
|
2 |
|
if (!empty($definition->defaultValue)) { |
26
|
1 |
|
$fieldConfig['defaultValue'] = self::astValueNodeToConfig($definition->defaultValue); |
27
|
|
|
} |
28
|
|
|
|
29
|
2 |
|
$directiveConfig = DirectiveNode::toConfig($definition); |
30
|
2 |
|
if (isset($directiveConfig['deprecationReason'])) { |
31
|
1 |
|
$fieldConfig['deprecationReason'] = $directiveConfig['deprecationReason']; |
32
|
|
|
} |
33
|
|
|
|
34
|
2 |
|
$config[$definition->name->value] = $fieldConfig; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
2 |
|
return $config; |
39
|
|
|
} |
40
|
|
|
|
41
|
1 |
|
private static function astValueNodeToConfig(ValueNode $valueNode) |
42
|
|
|
{ |
43
|
1 |
|
$config = null; |
44
|
1 |
|
switch ($valueNode->kind) { |
|
|
|
|
45
|
|
|
case NodeKind::INT: |
46
|
1 |
|
$config = intval($valueNode->value, 10); |
|
|
|
|
47
|
1 |
|
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
|
1 |
|
$config = $valueNode->value; |
|
|
|
|
57
|
1 |
|
break; |
58
|
|
|
|
59
|
|
|
case NodeKind::LST: |
60
|
1 |
|
$config = []; |
61
|
1 |
|
foreach ($valueNode->values as $node) { |
|
|
|
|
62
|
1 |
|
$config[] = self::astValueNodeToConfig($node); |
63
|
|
|
} |
64
|
1 |
|
break; |
65
|
|
|
|
66
|
|
|
case NodeKind::NULL: |
67
|
1 |
|
$config = null; |
68
|
1 |
|
break; |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
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: