1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Digia\GraphQL\Execution; |
4
|
|
|
|
5
|
|
|
use Digia\GraphQL\Error\GraphQLError; |
6
|
|
|
use Digia\GraphQL\Language\AST\Node\ArgumentNode; |
7
|
|
|
use Digia\GraphQL\Language\AST\Node\Behavior\DirectivesTrait; |
|
|
|
|
8
|
|
|
use Digia\GraphQL\Language\AST\Node\NodeInterface; |
9
|
|
|
use Digia\GraphQL\Language\AST\Node\DirectiveNode; |
10
|
|
|
use Digia\GraphQL\Language\AST\Node\FieldNode; |
11
|
|
|
use Digia\GraphQL\Language\AST\Node\NamedTypeNode; |
12
|
|
|
use Digia\GraphQL\Language\AST\Node\VariableNode; |
13
|
|
|
use Digia\GraphQL\Type\Definition\DirectiveInterface; |
14
|
|
|
use Digia\GraphQL\Type\Definition\Field; |
15
|
|
|
use Digia\GraphQL\Type\Definition\NonNullType; |
16
|
|
|
use function Digia\GraphQL\Language\valueFromAST; |
17
|
|
|
use function Digia\GraphQL\Util\find; |
18
|
|
|
use function Digia\GraphQL\Util\keyMap; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param Field|DirectiveInterface $definition |
22
|
|
|
* @param FieldNode|DirectiveNode $node |
23
|
|
|
* @param array $variableValues |
24
|
|
|
* @return array |
25
|
|
|
* @throws GraphQLError |
26
|
|
|
* @throws \Exception |
27
|
|
|
*/ |
28
|
|
|
function getArgumentValues($definition, NodeInterface $node, array $variableValues = []): array |
29
|
|
|
{ |
30
|
|
|
$coercedValues = []; |
31
|
|
|
$argumentDefinitions = $definition->getArguments(); |
32
|
|
|
$argumentNodes = $node->getArguments(); |
|
|
|
|
33
|
|
|
|
34
|
|
|
if (empty($argumentDefinitions) || empty($argumentNodes)) { |
35
|
|
|
return $coercedValues; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$argumentNodeMap = keyMap($argumentNodes, function (ArgumentNode $value) { |
39
|
|
|
return $value->getNameValue(); |
40
|
|
|
}); |
41
|
|
|
|
42
|
|
|
foreach ($argumentDefinitions as $argumentDefinition) { |
43
|
|
|
$name = $argumentDefinition->getName(); |
44
|
|
|
$argumentType = $argumentDefinition->getType(); |
45
|
|
|
/** @var ArgumentNode $argumentNode */ |
46
|
|
|
$argumentNode = $argumentNodeMap[$name]; |
47
|
|
|
$defaultValue = $argumentDefinition->getDefaultValue(); |
48
|
|
|
|
49
|
|
|
if (null === $argumentNode) { |
50
|
|
|
if (null === $defaultValue) { |
51
|
|
|
$coercedValues[$name] = $defaultValue; |
52
|
|
|
} elseif (!$argumentType instanceof NonNullType) { |
53
|
|
|
throw new GraphQLError( |
54
|
|
|
sprintf('Argument "%s" of required type "%s" was not provided.', $name, $argumentType), |
55
|
|
|
[$node] |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
} elseif ($argumentNode instanceof VariableNode) { |
59
|
|
|
$variableName = $argumentNode->getNameValue(); |
60
|
|
|
|
61
|
|
|
if (!empty($variableValues) && isset($variableValues[$variableName])) { |
62
|
|
|
// Note: this does not check that this variable value is correct. |
63
|
|
|
// This assumes that this query has been validated and the variable |
64
|
|
|
// usage here is of the correct type. |
65
|
|
|
$coercedValues[$name] = $variableValues[$variableName]; |
66
|
|
|
} elseif (null !== $defaultValue) { |
67
|
|
|
$coercedValues[$name] = $defaultValue; |
68
|
|
|
} elseif ($argumentType instanceof NonNullType) { |
69
|
|
|
throw new GraphQLError( |
70
|
|
|
sprintf( |
71
|
|
|
'Argument "%s" of required type "%s" was provided the variable "%s" which was not provided a runtime value.', |
72
|
|
|
$name, |
73
|
|
|
$argumentType, |
74
|
|
|
$variableName |
75
|
|
|
), |
76
|
|
|
[$argumentNode->getValue()] |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
} else { |
80
|
|
|
$valueNode = $argumentNode->getValue(); |
81
|
|
|
|
82
|
|
|
$coercedValue = valueFromAST($valueNode, $argumentType, $variableValues); |
83
|
|
|
|
84
|
|
|
if (null === $coercedValue) { |
85
|
|
|
// Note: ValuesOfCorrectType validation should catch this before |
86
|
|
|
// execution. This is a runtime check to ensure execution does not |
87
|
|
|
// continue with an invalid argument value. |
88
|
|
|
throw new GraphQLError( |
89
|
|
|
sprintf('Argument "%s" has invalid value %s.', $name, $valueNode), |
|
|
|
|
90
|
|
|
[$argumentNode->getValue()] |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param DirectiveInterface $directive |
99
|
|
|
* @param NodeInterface|DirectivesTrait $node |
100
|
|
|
* @param array $variableValues |
101
|
|
|
* @return array|null |
102
|
|
|
* @throws GraphQLError |
103
|
|
|
* @throws \Exception |
104
|
|
|
*/ |
105
|
|
|
function getDirectiveValues(DirectiveInterface $directive, NodeInterface $node, array $variableValues = []): ?array |
106
|
|
|
{ |
107
|
|
|
$directiveNode = $node->hasDirectives() |
|
|
|
|
108
|
|
|
? find($node->getDirectives(), function (NamedTypeNode $value) use ($directive) { |
|
|
|
|
109
|
|
|
return $value->getNameValue() === $directive->getName(); |
110
|
|
|
}) : null; |
111
|
|
|
|
112
|
|
|
if (null !== $directiveNode) { |
113
|
|
|
return getArgumentValues($directive, $directiveNode, $variableValues); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return null; |
117
|
|
|
} |
118
|
|
|
|
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