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\Definition\Builder; |
13
|
|
|
|
14
|
|
|
use GraphQL\Schema; |
15
|
|
|
use GraphQL\Type\Definition\Config; |
16
|
|
|
use Overblog\GraphQLBundle\Resolver\ResolverInterface; |
17
|
|
|
|
18
|
|
|
class SchemaBuilder |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var ResolverInterface |
22
|
|
|
*/ |
23
|
|
|
private $typeResolver; |
24
|
|
|
|
25
|
|
|
/** @var array */ |
26
|
|
|
private $typesMapping; |
27
|
|
|
|
28
|
|
|
/** @var bool */ |
29
|
|
|
private $enableValidation; |
30
|
|
|
|
31
|
25 |
|
public function __construct(ResolverInterface $typeResolver, array $typesMapping, $enableValidation = false) |
32
|
|
|
{ |
33
|
25 |
|
$this->typeResolver = $typeResolver; |
34
|
25 |
|
$this->typesMapping = $typesMapping; |
35
|
25 |
|
$this->enableValidation = $enableValidation; |
36
|
25 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param null|string $queryAlias |
40
|
|
|
* @param null|string $mutationAlias |
41
|
|
|
* @param null|string $subscriptionAlias |
42
|
|
|
* |
43
|
|
|
* @return Schema |
44
|
|
|
*/ |
45
|
25 |
|
public function create($queryAlias = null, $mutationAlias = null, $subscriptionAlias = null) |
46
|
|
|
{ |
47
|
25 |
|
$this->enableValidation ? Config::enableValidation() : Config::disableValidation(); |
48
|
25 |
|
$this->warmUpTypes(); |
49
|
|
|
|
50
|
|
|
$query = $this->typeResolver->resolve($queryAlias); |
51
|
|
|
$mutation = $this->typeResolver->resolve($mutationAlias); |
52
|
|
|
$subscription = $this->typeResolver->resolve($subscriptionAlias); |
53
|
|
|
|
54
|
|
|
return new Schema($query, $mutation, $subscription); |
55
|
|
|
} |
56
|
|
|
|
57
|
25 |
|
private function warmUpTypes() |
58
|
|
|
{ |
59
|
25 |
|
foreach ($this->typesMapping as $alias => $serviceId) { |
60
|
25 |
|
$this->typeResolver->resolve($alias); |
61
|
25 |
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|