|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is a part of GraphQL project. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Alexandr Viniychuk <[email protected]> |
|
6
|
|
|
* created: 5/19/16 8:58 AM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Youshido\GraphQL\Execution; |
|
10
|
|
|
|
|
11
|
|
|
use Youshido\GraphQL\Execution\Context\ExecutionContextInterface; |
|
12
|
|
|
use Youshido\GraphQL\Field\FieldInterface; |
|
13
|
|
|
use Youshido\GraphQL\Parser\Ast\Field; |
|
14
|
|
|
use Youshido\GraphQL\Parser\Ast\Query; |
|
15
|
|
|
use Youshido\GraphQL\Type\AbstractType; |
|
16
|
|
|
|
|
17
|
|
|
class ResolveInfo |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var FieldInterface */ |
|
20
|
|
|
protected $field; |
|
21
|
|
|
|
|
22
|
|
|
/** @var Field[] */ |
|
23
|
|
|
protected $fieldASTList; |
|
24
|
|
|
|
|
25
|
|
|
/** @var ExecutionContextInterface */ |
|
26
|
|
|
protected $executionContext; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* This property is to be used for DI in various scenario |
|
30
|
|
|
* Added to original class to keep backward compatibility |
|
31
|
|
|
* because of the way AbstractField::resolve has been declared |
|
32
|
|
|
* |
|
33
|
|
|
* @var mixed $container |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $container; |
|
36
|
|
|
|
|
37
|
51 |
|
public function __construct(FieldInterface $field, array $fieldASTList, ExecutionContextInterface $executionContext) |
|
38
|
|
|
{ |
|
39
|
51 |
|
$this->field = $field; |
|
40
|
51 |
|
$this->fieldASTList = $fieldASTList; |
|
41
|
51 |
|
$this->executionContext = $executionContext; |
|
42
|
51 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return ExecutionContextInterface |
|
46
|
|
|
*/ |
|
47
|
10 |
|
public function getExecutionContext() |
|
48
|
|
|
{ |
|
49
|
10 |
|
return $this->executionContext; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return FieldInterface |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function getField() |
|
56
|
|
|
{ |
|
57
|
1 |
|
return $this->field; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param string $fieldName |
|
62
|
|
|
* |
|
63
|
|
|
* @return null|Query|Field |
|
64
|
|
|
*/ |
|
65
|
1 |
|
public function getFieldAST($fieldName) |
|
66
|
|
|
{ |
|
67
|
1 |
|
$field = null; |
|
68
|
1 |
|
foreach ($this->getFieldASTList() as $fieldAST) { |
|
69
|
1 |
|
if ($fieldAST->getName() === $fieldName) { |
|
70
|
1 |
|
$field = $fieldAST; |
|
71
|
1 |
|
break; |
|
72
|
|
|
} |
|
73
|
1 |
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
return $field; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return Field[] |
|
80
|
|
|
*/ |
|
81
|
2 |
|
public function getFieldASTList() |
|
82
|
|
|
{ |
|
83
|
2 |
|
return $this->fieldASTList; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return AbstractType |
|
88
|
|
|
*/ |
|
89
|
4 |
|
public function getReturnType() |
|
90
|
|
|
{ |
|
91
|
4 |
|
return $this->field->getType(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
1 |
|
public function getContainer() |
|
95
|
|
|
{ |
|
96
|
1 |
|
return $this->executionContext->getContainer(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|