|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Digia\GraphQL\Validation; |
|
4
|
|
|
|
|
5
|
|
|
use Digia\GraphQL\Language\Node\DocumentNode; |
|
6
|
|
|
use Digia\GraphQL\Language\Visitor\ParallelVisitor; |
|
7
|
|
|
use Digia\GraphQL\Language\Visitor\TypeInfoVisitor; |
|
8
|
|
|
use Digia\GraphQL\SchemaValidator\SchemaValidatorInterface; |
|
9
|
|
|
use Digia\GraphQL\Type\SchemaInterface; |
|
10
|
|
|
use function Digia\GraphQL\Util\invariant; |
|
11
|
|
|
use Digia\GraphQL\Util\TypeInfo; |
|
12
|
|
|
use Digia\GraphQL\Validation\Rule\RuleInterface; |
|
13
|
|
|
use Digia\GraphQL\Validation\Rule\RulesBuilderInterface; |
|
|
|
|
|
|
14
|
|
|
use Digia\GraphQL\Validation\Rule\SupportedRules; |
|
15
|
|
|
|
|
16
|
|
|
class Validator implements ValidatorInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var ContextBuilderInterface |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $contextBuilder; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var SchemaValidatorInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $schemaValidator; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Validator constructor. |
|
30
|
|
|
* @param ContextBuilderInterface $contextBuilder |
|
31
|
|
|
* @param SchemaValidatorInterface $schemaValidator |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(ContextBuilderInterface $contextBuilder, SchemaValidatorInterface $schemaValidator) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->contextBuilder = $contextBuilder; |
|
36
|
|
|
$this->schemaValidator = $schemaValidator; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @inheritdoc |
|
41
|
|
|
*/ |
|
42
|
|
|
public function validate( |
|
43
|
|
|
SchemaInterface $schema, |
|
44
|
|
|
DocumentNode $document, |
|
45
|
|
|
?array $rules = null, |
|
46
|
|
|
?TypeInfo $typeInfo = null |
|
47
|
|
|
): array { |
|
48
|
|
|
invariant(null !== $document, 'Must provided document'); |
|
49
|
|
|
|
|
50
|
|
|
$this->schemaValidator->assertValid($schema); |
|
51
|
|
|
|
|
52
|
|
|
$typeInfo = $typeInfo ?? new TypeInfo($schema); |
|
53
|
|
|
$rules = $rules ?? SupportedRules::build(); |
|
54
|
|
|
|
|
55
|
|
|
$context = $this->contextBuilder->build($schema, $document, $typeInfo); |
|
56
|
|
|
|
|
57
|
|
|
$visitors = \array_map(function (RuleInterface $rule) use ($context) { |
|
58
|
|
|
return $rule->setContext($context); |
|
59
|
|
|
}, $rules); |
|
60
|
|
|
|
|
61
|
|
|
$visitor = new TypeInfoVisitor($typeInfo, new ParallelVisitor($visitors)); |
|
62
|
|
|
|
|
63
|
|
|
// Visit the whole document with each instance of all provided rules. |
|
64
|
|
|
$document->acceptVisitor($visitor); |
|
65
|
|
|
|
|
66
|
|
|
return $context->getErrors(); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths