1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Digia\GraphQL\Validation; |
4
|
|
|
|
5
|
|
|
use Digia\GraphQL\Error\GraphQLError; |
6
|
|
|
use Digia\GraphQL\Language\AST\Node\DocumentNode; |
7
|
|
|
use Digia\GraphQL\Type\Definition\Field; |
8
|
|
|
use Digia\GraphQL\Type\Definition\TypeInterface; |
9
|
|
|
use Digia\GraphQL\Type\SchemaInterface; |
10
|
|
|
use Digia\GraphQL\Util\TypeInfo; |
11
|
|
|
|
12
|
|
|
class ValidationContext |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var SchemaInterface |
16
|
|
|
*/ |
17
|
|
|
protected $schema; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var DocumentNode |
21
|
|
|
*/ |
22
|
|
|
protected $documentNode; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var TypeInfo |
26
|
|
|
*/ |
27
|
|
|
protected $typeInfo; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array|GraphQLError[] |
31
|
|
|
*/ |
32
|
|
|
protected $errors = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* ValidationContext constructor. |
36
|
|
|
* @param SchemaInterface $schema |
37
|
|
|
* @param DocumentNode $documentNode |
38
|
|
|
* @param TypeInfo $typeInfo |
39
|
|
|
*/ |
40
|
|
|
public function __construct(SchemaInterface $schema, DocumentNode $documentNode, TypeInfo $typeInfo) |
41
|
|
|
{ |
42
|
|
|
$this->schema = $schema; |
43
|
|
|
$this->documentNode = $documentNode; |
44
|
|
|
$this->typeInfo = $typeInfo; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param GraphQLError $error |
49
|
|
|
*/ |
50
|
|
|
public function reportError(GraphQLError $error): void |
51
|
|
|
{ |
52
|
|
|
$this->errors[] = $error; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return array|GraphQLError[] |
57
|
|
|
*/ |
58
|
|
|
public function getErrors(): array |
59
|
|
|
{ |
60
|
|
|
return $this->errors; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return TypeInterface|null |
65
|
|
|
*/ |
66
|
|
|
public function getParentType(): ?TypeInterface |
67
|
|
|
{ |
68
|
|
|
return $this->typeInfo->getParentType(); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return Field|null |
73
|
|
|
*/ |
74
|
|
|
public function getFieldDefinition(): ?Field |
75
|
|
|
{ |
76
|
|
|
return $this->typeInfo->getFieldDefinition(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return SchemaInterface |
81
|
|
|
*/ |
82
|
|
|
public function getSchema(): SchemaInterface |
83
|
|
|
{ |
84
|
|
|
return $this->schema; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|