1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Digia\GraphQL\Util; |
4
|
|
|
|
5
|
|
|
use Digia\GraphQL\Error\InvalidTypeException; |
6
|
|
|
use Digia\GraphQL\Error\InvariantException; |
7
|
|
|
use Digia\GraphQL\Error\ResolutionException; |
8
|
|
|
use Digia\GraphQL\Language\Node\ArgumentNode; |
9
|
|
|
use Digia\GraphQL\Language\Node\EnumValueNode; |
10
|
|
|
use Digia\GraphQL\Language\Node\ListValueNode; |
11
|
|
|
use Digia\GraphQL\Language\Node\NodeInterface; |
12
|
|
|
use Digia\GraphQL\Language\Node\NullValueNode; |
13
|
|
|
use Digia\GraphQL\Language\Node\ObjectFieldNode; |
14
|
|
|
use Digia\GraphQL\Language\Node\ObjectValueNode; |
15
|
|
|
use Digia\GraphQL\Language\Node\ValueNodeInterface; |
16
|
|
|
use Digia\GraphQL\Language\Node\VariableNode; |
17
|
|
|
use Digia\GraphQL\Type\Definition\EnumType; |
18
|
|
|
use Digia\GraphQL\Type\Definition\InputObjectType; |
19
|
|
|
use Digia\GraphQL\Type\Definition\InputTypeInterface; |
20
|
|
|
use Digia\GraphQL\Type\Definition\ListType; |
21
|
|
|
use Digia\GraphQL\Type\Definition\NonNullType; |
22
|
|
|
use Digia\GraphQL\Type\Definition\ScalarType; |
23
|
|
|
use Digia\GraphQL\Type\Definition\TypeInterface; |
24
|
|
|
use function Digia\GraphQL\printNode; |
25
|
|
|
|
26
|
|
|
class ValueHelper |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @param array $argumentsA |
30
|
|
|
* @param array $argumentsB |
31
|
|
|
* @return bool |
32
|
|
|
*/ |
33
|
|
|
function compareArguments(array $argumentsA, array $argumentsB): bool |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
if (\count($argumentsA) !== \count($argumentsB)) { |
36
|
|
|
return false; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return arrayEvery($argumentsA, function (ArgumentNode $argumentA) use ($argumentsB) { |
40
|
|
|
$argumentB = find($argumentsB, function (ArgumentNode $argument) use ($argumentA) { |
41
|
|
|
return $argument->getNameValue() === $argumentA->getNameValue(); |
42
|
|
|
}); |
43
|
|
|
|
44
|
|
|
if (null === $argumentB) { |
45
|
|
|
return false; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $this->compareValues($argumentA->getValue(), $argumentB->getValue()); |
49
|
|
|
}); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param $valueA |
54
|
|
|
* @param $valueB |
55
|
|
|
* @return bool |
56
|
|
|
*/ |
57
|
|
|
public function compareValues($valueA, $valueB): bool |
58
|
|
|
{ |
59
|
|
|
return printNode($valueA) === printNode($valueB); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.