Completed
Push — 8.x-3.x ( 01cbd2...7814d5 )
by Sebastian
10:18
created

Processor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B deferredResolve() 0 23 4
1
<?php
2
3
namespace Drupal\graphql\GraphQL\Execution;
4
5
use Youshido\GraphQL\Execution\DeferredResolverInterface;
6
use Youshido\GraphQL\Execution\DeferredResult;
7
use Youshido\GraphQL\Execution\Processor as BaseProcessor;
8
use Youshido\GraphQL\Field\FieldInterface;
9
use Youshido\GraphQL\Type\Enum\AbstractEnumType;
10
use Youshido\GraphQL\Type\Scalar\AbstractScalarType;
11
12
class Processor extends BaseProcessor {
13
14
  /**
15
   * {@inheritdoc}
16
   */
17
  protected function deferredResolve($resolvedValue, FieldInterface $field, callable $callback) {
18
    if ($resolvedValue instanceof DeferredResolverInterface) {
19
      $deferredResult = new DeferredResult($resolvedValue, function ($resolvedValue) use ($field, $callback) {
20
        // Allow nested deferred resolvers.
21
        return $this->deferredResolve($resolvedValue, $field, $callback);
22
      });
23
24
      // Whenever we stumble upon a deferred resolver, add it to the queue to be
25
      // resolved later.
26
      $type = $field->getType()->getNamedType();
27
      if ($type instanceof AbstractScalarType || $type instanceof AbstractEnumType) {
28
        array_push($this->deferredResultsLeaf, $deferredResult);
29
      }
30
      else {
31
        array_push($this->deferredResultsComplex, $deferredResult);
32
      }
33
34
      return $deferredResult;
35
    }
36
37
    // For simple values, invoke the callback immediately.
38
    return $callback($resolvedValue);
39
  }
40
41
}