• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

overblog / GraphQLBundle / 17326055084

29 Aug 2025 02:08PM UTC coverage: 98.279% (-0.09%) from 98.368%
17326055084

push

github

web-flow
Merge pull request #1203 from Nyholm/reset

add kernel.reset tag to allow clearing memory between request

0 of 4 new or added lines in 2 files covered. (0.0%)

4339 of 4415 relevant lines covered (98.28%)

39.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.0
/src/Resolver/TypeResolver.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Overblog\GraphQLBundle\Resolver;
6

7
use GraphQL\Type\Definition\Type;
8
use Overblog\GraphQLBundle\Event\Events;
9
use Overblog\GraphQLBundle\Event\TypeLoadedEvent;
10
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
11

12
use function sprintf;
13

14
class TypeResolver extends AbstractResolver
15
{
16
    private array $cache = [];
17
    private ?string $currentSchemaName = null;
18
    private EventDispatcherInterface $dispatcher;
19
    private bool $ignoreUnresolvableException = false;
20

21
    public function setDispatcher(EventDispatcherInterface $dispatcher): void
22
    {
23
        $this->dispatcher = $dispatcher;
139✔
24
    }
139✔
25

26
    public function setCurrentSchemaName(?string $currentSchemaName): void
27
    {
28
        $this->currentSchemaName = $currentSchemaName;
120✔
29
    }
120✔
30

31
    public function setIgnoreUnresolvableException(bool $ignoreUnresolvableException): void
32
    {
33
        $this->ignoreUnresolvableException = $ignoreUnresolvableException;
8✔
34
    }
8✔
35

36
    /**
37
     * @param mixed $solution
38
     */
39
    protected function onLoadSolution($solution): void
40
    {
41
        if (isset($this->dispatcher)) {
128✔
42
            // @phpstan-ignore-next-line (only for Symfony 4.4)
43
            $this->dispatcher->dispatch(new TypeLoadedEvent($solution, $this->currentSchemaName), Events::TYPE_LOADED);
126✔
44
        }
45
    }
128✔
46

47
    /**
48
     * @param string $alias
49
     */
50
    public function resolve($alias): ?Type
51
    {
52
        if (null === $alias) {
128✔
53
            return null;
119✔
54
        }
55

56
        if (!isset($this->cache[$alias])) {
128✔
57
            $type = $this->baseType($alias);
128✔
58
            $this->cache[$alias] = $type;
125✔
59
            if (isset($type->name) && $type->name !== $alias) {
125✔
60
                $this->cache[$type->name] = $type;
4✔
61
            }
62
        }
63

64
        return $this->cache[$alias];
125✔
65
    }
66

67
    private function baseType(string $alias): ?Type
68
    {
69
        $type = $this->getSolution($alias);
128✔
70
        if (null === $type && !$this->ignoreUnresolvableException) {
127✔
71
            throw new UnresolvableException(
3✔
72
                sprintf('Could not find type with alias "%s". Did you forget to define it?', $alias)
3✔
73
            );
74
        }
75

76
        return $type;
125✔
77
    }
78

79
    public function reset(): void
80
    {
NEW
81
        $this->cache = [];
×
NEW
82
    }
×
83

84
    protected function supportedSolutionClass(): ?string
85
    {
86
        return Type::class;
×
87
    }
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc