ViewResultType   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A applies() 0 11 4
1
<?php
2
3
namespace Drupal\graphql_views\Plugin\GraphQL\Types;
4
5
use Drupal\graphql\GraphQL\Execution\ResolveContext;
6
use Drupal\graphql\Plugin\GraphQL\Types\TypePluginBase;
7
use GraphQL\Type\Definition\ResolveInfo;
8
9
/**
10
 * Expose views as root fields.
11
 *
12
 * @GraphQLType(
13
 *   id = "view_result_type",
14
 *   provider = "views",
15
 *   unions = {"ViewResult"},
16
 *   deriver = "Drupal\graphql_views\Plugin\Deriver\Types\ViewResultTypeDeriver"
17
 * )
18
 */
19
class ViewResultType extends TypePluginBase {
20
21
  /**
22
   * {@inheritdoc}
23
   */
24
  public function applies($object, ResolveContext $context, ResolveInfo $info) {
25
    if (isset($object['view'])) {
26
      /* @var \Drupal\views\Entity\View $view */
27
      $view = $object['view'];
28
      if ($this->pluginDefinition['view'] === $view->id() && $this->pluginDefinition['display'] == $view->current_display) {
29
        return TRUE;
30
      }
31
    }
32
33
    return parent::applies($object, $context, $info);
34
  }
35
36
}
37