Skip to content

Commit 49067c8

Browse files
authored
Merge pull request #2 from TylerFiekens/update-config
Feat: Update Config
2 parents df14da6 + e8328ad commit 49067c8

File tree

3 files changed

+33
-34
lines changed

3 files changed

+33
-34
lines changed

config/graphqlite.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
| You can put a single namespace, or an array of namespaces.
1818
|
1919
*/
20-
'controllers' => 'App\\Http\\Controllers',
21-
'types' => 'App\\',
22-
'debug' => DebugFlag::RETHROW_UNSAFE_EXCEPTIONS,
20+
'queries' => 'App\\GraphQL\\Queries',
21+
'mutations' => 'App\\GraphQL\\Mutations',
22+
'types' => 'App\\GraphQL\\Types',
23+
24+
'disable_introspection' => env('GRAPHQLITE_DISABLE_INTROSPECTION', false),
25+
26+
'debug' => env('GRAPHQLITE_DEBUG', DebugFlag::NONE),
2327
'uri' => env('GRAPHQLITE_URI', '/graphql'),
2428
'middleware' => ['web'],
2529

src/Providers/GraphQLiteServiceProvider.php

+25-30
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace TheCodingMachine\GraphQLite\Laravel\Providers;
44

5-
use GraphQL\Type\Definition\ObjectType;
6-
use GraphQL\Type\SchemaConfig;
7-
use Illuminate\Contracts\Auth\Access\Gate;
5+
use GraphQL\GraphQL;
6+
use GraphQL\Validator\DocumentValidator;
7+
use GraphQL\Validator\Rules\DisableIntrospection;
88
use Illuminate\Contracts\Auth\Factory as AuthFactory;
99
use Illuminate\Contracts\Events\Dispatcher;
1010
use Laminas\Diactoros\ResponseFactory;
@@ -26,7 +26,6 @@
2626
use TheCodingMachine\GraphQLite\Laravel\Console\Commands\GraphqliteExportSchema;
2727
use TheCodingMachine\GraphQLite\Laravel\Listeners\CachePurger;
2828
use TheCodingMachine\GraphQLite\Laravel\Mappers\Parameters\ValidateFieldMiddleware;
29-
use TheCodingMachine\GraphQLite\Laravel\Mappers\PaginatorTypeMapper;
3029
use TheCodingMachine\GraphQLite\Laravel\Mappers\PaginatorTypeMapperFactory;
3130
use TheCodingMachine\GraphQLite\Laravel\Security\AuthenticationService;
3231
use TheCodingMachine\GraphQLite\Laravel\Security\AuthorizationService;
@@ -52,12 +51,7 @@
5251

5352
class GraphQLiteServiceProvider extends ServiceProvider
5453
{
55-
/**
56-
* Bootstrap the application services.
57-
*
58-
* @return void
59-
*/
60-
public function boot(Dispatcher $events)
54+
public function boot(Dispatcher $events): void
6155
{
6256
$this->publishes([
6357
__DIR__.'/../../config/graphqlite.php' => config_path('graphqlite.php'),
@@ -67,12 +61,7 @@ public function boot(Dispatcher $events)
6761
$events->listen('cache:clearing', CachePurger::class);
6862
}
6963

70-
/**
71-
* Register the application services.
72-
*
73-
* @return void
74-
*/
75-
public function register()
64+
public function register(): void
7665
{
7766
$this->commands([
7867
GraphqliteExportSchema::class,
@@ -120,6 +109,7 @@ public function register()
120109
$serverConfig->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter']);
121110
$serverConfig->setErrorsHandler([WebonyxErrorHandler::class, 'errorHandler']);
122111
$serverConfig->setContext(new Context());
112+
123113
return $serverConfig;
124114
});
125115

@@ -150,20 +140,28 @@ public function register()
150140
$service->setAuthenticationService($app[AuthenticationService::class]);
151141
$service->setAuthorizationService($app[AuthorizationService::class]);
152142
$service->addParameterMiddleware($app[ValidateFieldMiddleware::class]);
153-
154143
$service->addTypeMapperFactory($app[PaginatorTypeMapperFactory::class]);
155144

156-
$controllers = config('graphqlite.controllers', 'App\\Http\\Controllers');
157-
if (!is_iterable($controllers)) {
158-
$controllers = [ $controllers ];
145+
$queries = config('graphqlite.queries', 'App\\GraphQL\\Queries');
146+
if (!is_iterable($queries)) {
147+
$queries = [ $queries ];
159148
}
160-
$types = config('graphqlite.types', 'App\\');
161-
if (!is_iterable($types)) {
162-
$types = [ $types ];
149+
foreach ($queries as $namespace) {
150+
$service->addControllerNamespace($namespace);
151+
}
152+
153+
$mutations = config('graphqlite.mutations', 'App\\GraphQL\\Mutations');
154+
if (!is_iterable($mutations)) {
155+
$mutations = [ $mutations ];
163156
}
164-
foreach ($controllers as $namespace) {
157+
foreach ($mutations as $namespace) {
165158
$service->addControllerNamespace($namespace);
166159
}
160+
161+
$types = config('graphqlite.types', 'App\\GraphQL\\Types');
162+
if (!is_iterable($types)) {
163+
$types = [ $types ];
164+
}
167165
foreach ($types as $namespace) {
168166
$service->addTypeNamespace($namespace);
169167
}
@@ -181,14 +179,11 @@ public function register()
181179

182180
return $schemaFactory->createSchema();
183181
});
182+
183+
DocumentValidator::addRule(new DisableIntrospection(config('graphqlite.disable_introspection', false)));
184184
}
185185

186-
/**
187-
* Get the services provided by the provider.
188-
*
189-
* @return array
190-
*/
191-
public function provides()
186+
public function provides(): array
192187
{
193188
return [
194189
SchemaFactory::class,

tests/Fixtures/App/Http/Controllers/TestController.php tests/Fixtures/App/GraphQL/Queries/TestController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33

4-
namespace App\Http\Controllers;
4+
namespace App\GraphQL\Queries;
55

66

77
use Illuminate\Pagination\LengthAwarePaginator;

0 commit comments

Comments
 (0)