Completed
Pull Request — 8.x-3.x (#494)
by Philipp
02:39
created

getSchemaResponseMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
}