Completed
Pull Request — 8.x-3.x (#525)
by Sebastian
02:06
created

RequestController::handleBatchRequest()   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 84
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 46
nc 4
nop 2
dl 0
loc 84
rs 6.5389
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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