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

Processor::deferredResolve()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 3
nop 3
dl 0
loc 23
rs 8.7972
c 0
b 0
f 0
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
}