Issues (645)

src/Controller/RequestController.php (3 issues)

1
<?php
2
3
namespace Drupal\graphql\Controller;
4
5
use Drupal\Core\Cache\CacheableJsonResponse;
0 ignored issues
show
The type Drupal\Core\Cache\CacheableJsonResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
0 ignored issues
show
The type Drupal\Core\DependencyIn...ainerInjectionInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Drupal\graphql\GraphQL\Execution\QueryProcessor;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
0 ignored issues
show
The type Symfony\Component\Depend...tion\ContainerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
   * The service configuration parameters.
24
   *
25
   * @var array
26
   */
27
  protected $parameters;
28
29
  /**
30
   * {@inheritdoc}
31
   */
32
  public static function create(ContainerInterface $container) {
33
    return new static(
34
      $container->get('graphql.query_processor'),
35
      $container->getParameter('graphql.config')
36
    );
37
  }
38
39
  /**
40
   * RequestController constructor.
41
   *
42
   * @param \Drupal\graphql\GraphQL\Execution\QueryProcessor $processor
43
   *   The query processor.
44
   * @param array $parameters
45
   *   The service configuration parameters.
46
   */
47
  public function __construct(QueryProcessor $processor, array $parameters) {
48
    $this->processor = $processor;
49
    $this->parameters = $parameters;
50
  }
51
52
  /**
53
   * Handles graphql requests.
54
   *
55
   * @param string $schema
56
   *   The name of the schema.
57
   * @param \GraphQL\Server\OperationParams|\GraphQL\Server\OperationParams[] $operations
58
   *   The graphql operation(s) to execute.
59
   *
60
   * @return \Drupal\Core\Cache\CacheableJsonResponse
61
   *   The JSON formatted response.
62
   *
63
   * @throws \Drupal\Component\Plugin\Exception\PluginException
64
   */
65
  public function handleRequest($schema, $operations) {
66
    if (is_array($operations)) {
67
      return $this->handleBatch($schema, $operations);
68
    }
69
70
    return $this->handleSingle($schema, $operations);
71
  }
72
73
  /**
74
   * @param $schema
75
   * @param $operations
76
   * @param array $globals
77
   *
78
   * @return \Drupal\Core\Cache\CacheableJsonResponse
79
   * @throws \Drupal\Component\Plugin\Exception\PluginException
80
   */
81
  protected function handleSingle($schema, $operations) {
82
    $result = $this->processor->processQuery($schema, $operations);
83
    $response = new CacheableJsonResponse($result);
84
    $response->addCacheableDependency($result);
85
    return $response;
86
  }
87
88
  /**
89
   * @param $schema
90
   * @param $operations
91
   * @param array $globals
92
   *
93
   * @return \Drupal\Core\Cache\CacheableJsonResponse
94
   * @throws \Drupal\Component\Plugin\Exception\PluginException
95
   */
96
  protected function handleBatch($schema, $operations) {
97
    $result = $this->processor->processQuery($schema, $operations);
98
    $response = new CacheableJsonResponse($result);
99
100
    // In case of a batch request, the result is an array.
101
    $dependencies = is_array($operations) ? $result : [$result];
102
    foreach ($dependencies as $dependency) {
103
      $response->addCacheableDependency($dependency);
104
    }
105
106
    return $response;
107
  }
108
109
}
110