1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\graphql\Controller; |
4
|
|
|
|
5
|
|
|
use Drupal\Core\Cache\Cache; |
6
|
|
|
use Drupal\Core\Cache\CacheableJsonResponse; |
7
|
|
|
use Drupal\Core\Cache\CacheableMetadata; |
8
|
|
|
use Drupal\Core\Cache\CacheableResponseInterface; |
9
|
|
|
use Drupal\Core\Cache\RefinableCacheableDependencyInterface; |
10
|
|
|
use Drupal\Core\Config\Config; |
11
|
|
|
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; |
12
|
|
|
use Drupal\Core\Render\RenderContext; |
13
|
|
|
use Drupal\Core\Render\RendererInterface; |
14
|
|
|
use Drupal\Core\Url; |
15
|
|
|
use Drupal\graphql\GraphQL\Execution\QueryProcessor; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
18
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
19
|
|
|
use Symfony\Component\HttpFoundation\Response; |
20
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Handles GraphQL requests. |
24
|
|
|
*/ |
25
|
|
|
class RequestController implements ContainerInjectionInterface { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The query processor. |
29
|
|
|
* |
30
|
|
|
* @var \Drupal\graphql\GraphQL\Execution\QueryProcessor |
31
|
|
|
*/ |
32
|
|
|
protected $processor; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
public static function create(ContainerInterface $container) { |
38
|
|
|
return new static($container->get('graphql.query_processor')); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* RequestController constructor. |
43
|
|
|
* |
44
|
|
|
* @param \Drupal\graphql\GraphQL\Execution\QueryProcessor $processor |
45
|
|
|
* The query processor. |
46
|
|
|
*/ |
47
|
|
|
public function __construct(QueryProcessor $processor) { |
48
|
|
|
$this->processor = $processor; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Handles GraphQL requests. |
53
|
|
|
* |
54
|
|
|
* @param string $schema |
55
|
|
|
* The name of the schema. |
56
|
|
|
* @param \GraphQL\Server\OperationParams|\GraphQL\Server\OperationParams[] $operations |
57
|
|
|
* The graphql operation(s) to execute. |
58
|
|
|
* |
59
|
|
|
* @return \Drupal\Core\Cache\CacheableJsonResponse |
60
|
|
|
* The JSON formatted response. |
61
|
|
|
*/ |
62
|
|
|
public function handleRequest($schema, $operations) { |
63
|
|
|
$result = $this->processor->processQuery($schema, $operations); |
64
|
|
|
$response = new CacheableJsonResponse($result); |
65
|
|
|
$response->addCacheableDependency($result); |
66
|
|
|
return $response; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|