forked from magento/graphql-ce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryProcessor.php
More file actions
87 lines (79 loc) · 2.43 KB
/
QueryProcessor.php
File metadata and controls
87 lines (79 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Framework\GraphQl\Query;
use Magento\Framework\GraphQl\Exception\ExceptionFormatter;
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
use Magento\Framework\GraphQl\Schema;
/**
* Wrapper for GraphQl execution of a schema
*/
class QueryProcessor
{
/**
* @var ExceptionFormatter
*/
private $exceptionFormatter;
/**
* @var QueryComplexityLimiter
*/
private $queryComplexityLimiter;
/**
* @var \Magento\Framework\GraphQl\Query\ErrorHandlerInterface
*/
private $errorHandler;
/**
* @param ExceptionFormatter $exceptionFormatter
* @param QueryComplexityLimiter $queryComplexityLimiter
*
* @param \Magento\Framework\GraphQl\Query\ErrorHandlerInterface $errorHandler
* @SuppressWarnings(PHPMD.LongVariable)
*/
public function __construct(
ExceptionFormatter $exceptionFormatter,
QueryComplexityLimiter $queryComplexityLimiter,
ErrorHandlerInterface $errorHandler
) {
$this->exceptionFormatter = $exceptionFormatter;
$this->queryComplexityLimiter = $queryComplexityLimiter;
$this->errorHandler = $errorHandler;
}
/**
* Process a GraphQl query according to defined schema
*
* @param Schema $schema
* @param string $source
* @param ContextInterface $contextValue
* @param array|null $variableValues
* @param string|null $operationName
* @return Promise|array
*/
public function process(
Schema $schema,
string $source,
ContextInterface $contextValue = null,
array $variableValues = null,
string $operationName = null
) : array {
if (!$this->exceptionFormatter->shouldShowDetail()) {
$this->queryComplexityLimiter->execute();
}
$rootValue = null;
return \GraphQL\GraphQL::executeQuery(
$schema,
$source,
$rootValue,
$contextValue,
$variableValues,
$operationName
)->setErrorsHandler(
[$this->errorHandler, 'handle']
)->toArray(
$this->exceptionFormatter->shouldShowDetail() ?
\GraphQL\Error\Debug::INCLUDE_DEBUG_MESSAGE : false
);
}
}