JsonResponseContent::resolveValues()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql_json\Plugin\GraphQL\Fields;
4
5
use Drupal\graphql\GraphQL\Execution\ResolveContext;
6
use Drupal\graphql_core\Plugin\GraphQL\Fields\Routing\Response\ResponseContent;
7
use GraphQL\Type\Definition\ResolveInfo;
8
9
/**
10
 * Get the response content of an internal or external request as json object.
11
 *
12
 * @GraphQLField(
13
 *   id = "json_response_content",
14
 *   secure = true,
15
 *   name = "json",
16
 *   type = "JsonNode",
17
 *   parents = {"InternalResponse", "ExternalResponse"}
18
 * )
19
 */
20
class JsonResponseContent extends ResponseContent {
21
22
  /**
23
   * {@inheritdoc}
24
   */
25
  protected function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) {
26
    foreach (parent::resolveValues($value, $args, $context, $info) as $item) {
27
      if ($data = json_decode($item, TRUE)) {
28
        yield $data;
29
      }
30
    }
31
  }
32
33
}
34