1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OverblogGraphQLBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Overblog\GraphQLBundle\Resolver; |
13
|
|
|
|
14
|
|
|
use GraphQL\Type\Definition\Type; |
15
|
|
|
|
16
|
|
|
class TypeResolver extends AbstractResolver |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param string $alias |
20
|
|
|
* |
21
|
|
|
* @return \GraphQL\Type\Definition\Type |
22
|
|
|
*/ |
23
|
33 |
|
public function resolve($alias) |
24
|
|
|
{ |
25
|
33 |
|
if (null !== $type = $this->cache->fetch($alias)) { |
26
|
30 |
|
return $type; |
27
|
|
|
} |
28
|
|
|
|
29
|
33 |
|
$type = $this->getType($alias); |
30
|
25 |
|
|
31
|
|
|
$this->cache->save($alias, $type); |
32
|
|
|
|
33
|
33 |
|
return $type; |
34
|
13 |
|
} |
35
|
|
|
|
36
|
|
|
private function getType($alias) |
37
|
32 |
|
{ |
38
|
7 |
|
if (!is_string($alias)) { |
39
|
|
|
return $alias; |
40
|
|
|
} |
41
|
|
|
// Non-Null |
42
|
7 |
|
if ('!' === $alias[strlen($alias) - 1]) { |
43
|
|
|
return Type::nonNull($this->getType(substr($alias, 0, -1))); |
44
|
|
|
} |
45
|
28 |
|
// List |
46
|
27 |
|
if ('[' === $alias[0]) { |
47
|
|
|
if (']' !== $alias[strlen($alias) - 1]) { |
48
|
27 |
|
throw new UnresolvableException(sprintf('Invalid type "%s"', $alias)); |
49
|
|
|
} |
50
|
|
|
|
51
|
28 |
|
return Type::listOf($this->getType(substr($alias, 1, -1))); |
52
|
|
|
} |
53
|
28 |
|
|
54
|
|
|
$type = $this->getSolution($alias); |
55
|
28 |
|
if (null === $type) { |
56
|
|
|
throw new UnresolvableException( |
57
|
28 |
|
sprintf('Unknown type with alias "%s" (verified service tag)', $alias) |
58
|
1 |
|
); |
59
|
1 |
|
} |
60
|
1 |
|
|
61
|
|
|
return $type; |
62
|
|
|
} |
63
|
27 |
|
|
64
|
|
|
protected function supportedSolutionClass() |
65
|
|
|
{ |
66
|
28 |
|
return 'GraphQL\\Type\\Definition\\Type'; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|