1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\graphql\Cache; |
4
|
|
|
|
5
|
|
|
use Drupal\Core\Cache\CacheableJsonResponse; |
6
|
|
|
use Drupal\Core\Cache\CacheableMetadata; |
7
|
|
|
use Drupal\graphql\GraphQL\Execution\QueryResult; |
8
|
|
|
|
9
|
|
|
class CacheableQueryResponse extends CacheableJsonResponse { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Cache metadata collected during query execution. |
13
|
|
|
* |
14
|
|
|
* @var \Drupal\Core\Cache\CacheableDependencyInterface |
15
|
|
|
*/ |
16
|
|
|
protected $responseMetadata; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Static response cache metadata from the schema. |
20
|
|
|
* |
21
|
|
|
* @var \Drupal\Core\Cache\CacheableDependencyInterface |
22
|
|
|
*/ |
23
|
|
|
protected $schemaResponseMetadata; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* CacheableQueryResponse constructor. |
27
|
|
|
* |
28
|
|
|
* @param \Drupal\graphql\GraphQL\Execution\QueryResult $data |
29
|
|
|
* The graphql query result object. |
30
|
|
|
* @param int $status |
31
|
|
|
* The http status code of the response. |
32
|
|
|
* @param array $headers |
33
|
|
|
* The http headers of the response. |
34
|
|
|
*/ |
35
|
|
|
public function __construct(QueryResult $data, $status = 200, array $headers = []) { |
36
|
|
|
parent::__construct($data->getData(), $status, $headers); |
37
|
|
|
|
38
|
|
|
$this->responseMetadata = $data->getResponseMetadata(); |
39
|
|
|
$this->schemaResponseMetadata = $data->getSchemaResponseMetadata(); |
40
|
|
|
|
41
|
|
|
// Extract the cacheability metadata from the query result object. |
42
|
|
|
$this->cacheabilityMetadata = new CacheableMetadata(); |
43
|
|
|
$this->cacheabilityMetadata->addCacheableDependency($data); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Gets the response cache metadata. |
48
|
|
|
* |
49
|
|
|
* @return \Drupal\Core\Cache\CacheableDependencyInterface |
50
|
|
|
* The response cache metadata. |
51
|
|
|
*/ |
52
|
|
|
public function getResponseMetadata() { |
53
|
|
|
return $this->responseMetadata; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Gets the schema's response cache metadata. |
58
|
|
|
* |
59
|
|
|
* @return \Drupal\Core\Cache\CacheableDependencyInterface |
60
|
|
|
* The schema's response cache metadata. |
61
|
|
|
*/ |
62
|
|
|
public function getSchemaResponseMetadata() { |
63
|
|
|
return $this->schemaResponseMetadata; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
} |