1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Digia\Lumen\GraphQL; |
4
|
|
|
|
5
|
|
|
use Digia\Lumen\GraphQL\Contracts\TypeResolverInterface; |
6
|
|
|
use Digia\Lumen\GraphQL\Exceptions\InvalidConfigurationException; |
7
|
|
|
use Digia\Lumen\GraphQL\Http\Middleware\GraphiQLTokenMiddleware; |
8
|
|
|
use Illuminate\Contracts\Cache\Repository as CacheRepository; |
9
|
|
|
use Illuminate\Support\ServiceProvider; |
10
|
|
|
use Laravel\Lumen\Application; |
11
|
|
|
use Youshido\GraphQL\Execution\Processor; |
12
|
|
|
|
13
|
|
|
class GraphQLServiceProvider extends ServiceProvider |
14
|
|
|
{ |
15
|
|
|
const CONFIG_KEY = 'graphql'; |
16
|
|
|
/** |
17
|
|
|
* @inheritdoc |
18
|
|
|
*/ |
19
|
|
|
public function register() |
20
|
|
|
{ |
21
|
|
|
// In Lumen application configuration files needs to be loaded implicitly |
22
|
|
|
if ($this->app instanceof \Laravel\Lumen\Application) { |
23
|
|
|
$this->app->configure(self::CONFIG_KEY); |
24
|
|
|
} else { |
25
|
|
|
$this->publishes([$this->configPath() => config_path('graphql.php')]); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
// Load graphiql view |
28
|
|
|
$this->loadViewsFrom(dirname(__DIR__) . '/resources/views', 'graphql'); |
29
|
|
|
// Register bindings |
30
|
|
|
$this->registerBindings(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Register bindings. |
35
|
|
|
* |
36
|
|
|
* @throws InvalidConfigurationException |
37
|
|
|
*/ |
38
|
|
|
public function registerBindings() |
39
|
|
|
{ |
40
|
|
|
$config = $this->app['config']->get('graphql'); |
41
|
|
|
$this->validateConfig($config); |
42
|
|
|
|
43
|
|
|
// Bind things to the container |
44
|
|
|
$this->app->singleton(GraphQLService::class, function (Application $app) use ($config) { |
45
|
|
|
$processor = $config['processor'] ?? Processor::class; |
46
|
|
|
|
47
|
|
|
return new GraphQLService(new $processor(new $config['schema']), $app->make(CacheRepository::class)); |
48
|
|
|
}); |
49
|
|
|
|
50
|
|
|
$this->app->singleton(TypeResolverInterface::class, function () use ($config) { |
51
|
|
|
return new $config['type_resolver'](); |
52
|
|
|
}); |
53
|
|
|
|
54
|
|
|
$this->app->bind(GraphiQLTokenMiddleware::class, function () use ($config) { |
55
|
|
|
return new GraphiQLTokenMiddleware($config['enable_graphiql'], $config['graphiql_token'] ?? null); |
56
|
|
|
}); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param array $config |
61
|
|
|
* |
62
|
|
|
* @throws InvalidConfigurationException |
63
|
|
|
*/ |
64
|
|
|
protected function validateConfig(array $config) |
65
|
|
|
{ |
66
|
|
|
if (!isset($config['schema'])) { |
67
|
|
|
throw new InvalidConfigurationException('Configuration value `schema` is required.'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if (!isset($config['type_resolver'])) { |
71
|
|
|
throw new InvalidConfigurationException('Configuration value `type_resolver` is required.'); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.