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\Type\Schema; |
15
|
|
|
use Overblog\GraphQLBundle\Resolver\ResolverInterface; |
16
|
|
|
|
17
|
|
|
class SchemaBuilder |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var ResolverInterface |
21
|
|
|
*/ |
22
|
|
|
private $typeResolver; |
23
|
|
|
|
24
|
|
|
/** @var bool */ |
25
|
|
|
private $enableValidation; |
26
|
|
|
|
27
|
15 |
|
public function __construct(ResolverInterface $typeResolver, $enableValidation = false) |
28
|
|
|
{ |
29
|
15 |
|
$this->typeResolver = $typeResolver; |
30
|
15 |
|
$this->enableValidation = $enableValidation; |
31
|
15 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param null|string $queryAlias |
35
|
|
|
* @param null|string $mutationAlias |
36
|
|
|
* @param null|string $subscriptionAlias |
37
|
|
|
* |
38
|
|
|
* @return Schema |
39
|
|
|
*/ |
40
|
15 |
|
public function create($queryAlias = null, $mutationAlias = null, $subscriptionAlias = null) |
41
|
|
|
{ |
42
|
15 |
|
$query = $this->typeResolver->resolve($queryAlias); |
43
|
15 |
|
$mutation = $this->typeResolver->resolve($mutationAlias); |
44
|
15 |
|
$subscription = $this->typeResolver->resolve($subscriptionAlias); |
45
|
|
|
|
46
|
|
|
$config = [ |
47
|
15 |
|
'query' => $query, |
48
|
15 |
|
'mutation' => $mutation, |
49
|
15 |
|
'subscription' => $subscription, |
50
|
15 |
|
]; |
51
|
|
|
|
52
|
15 |
|
if ($this->enableValidation) { |
53
|
|
|
// right now config.types is required when using "assertValid" |
54
|
14 |
|
$config['types'] = $this->typeResolver->getSolutions(); |
55
|
14 |
|
$schema = new Schema($config); |
56
|
14 |
|
$schema->assertValid(); |
57
|
14 |
|
} else { |
58
|
1 |
|
$config['typeLoader'] = [$this->typeResolver, 'resolve']; |
59
|
1 |
|
$schema = new Schema($config); |
60
|
|
|
} |
61
|
|
|
|
62
|
15 |
|
return $schema; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|