2
2
3
3
namespace TheCodingMachine \GraphQLite \Laravel \Providers ;
4
4
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 ;
8
8
use Illuminate \Contracts \Auth \Factory as AuthFactory ;
9
9
use Illuminate \Contracts \Events \Dispatcher ;
10
10
use Laminas \Diactoros \ResponseFactory ;
26
26
use TheCodingMachine \GraphQLite \Laravel \Console \Commands \GraphqliteExportSchema ;
27
27
use TheCodingMachine \GraphQLite \Laravel \Listeners \CachePurger ;
28
28
use TheCodingMachine \GraphQLite \Laravel \Mappers \Parameters \ValidateFieldMiddleware ;
29
- use TheCodingMachine \GraphQLite \Laravel \Mappers \PaginatorTypeMapper ;
30
29
use TheCodingMachine \GraphQLite \Laravel \Mappers \PaginatorTypeMapperFactory ;
31
30
use TheCodingMachine \GraphQLite \Laravel \Security \AuthenticationService ;
32
31
use TheCodingMachine \GraphQLite \Laravel \Security \AuthorizationService ;
52
51
53
52
class GraphQLiteServiceProvider extends ServiceProvider
54
53
{
55
- /**
56
- * Bootstrap the application services.
57
- *
58
- * @return void
59
- */
60
- public function boot (Dispatcher $ events )
54
+ public function boot (Dispatcher $ events ): void
61
55
{
62
56
$ this ->publishes ([
63
57
__DIR__ .'/../../config/graphqlite.php ' => config_path ('graphqlite.php ' ),
@@ -67,12 +61,7 @@ public function boot(Dispatcher $events)
67
61
$ events ->listen ('cache:clearing ' , CachePurger::class);
68
62
}
69
63
70
- /**
71
- * Register the application services.
72
- *
73
- * @return void
74
- */
75
- public function register ()
64
+ public function register (): void
76
65
{
77
66
$ this ->commands ([
78
67
GraphqliteExportSchema::class,
@@ -120,6 +109,7 @@ public function register()
120
109
$ serverConfig ->setErrorFormatter ([WebonyxErrorHandler::class, 'errorFormatter ' ]);
121
110
$ serverConfig ->setErrorsHandler ([WebonyxErrorHandler::class, 'errorHandler ' ]);
122
111
$ serverConfig ->setContext (new Context ());
112
+
123
113
return $ serverConfig ;
124
114
});
125
115
@@ -150,20 +140,28 @@ public function register()
150
140
$ service ->setAuthenticationService ($ app [AuthenticationService::class]);
151
141
$ service ->setAuthorizationService ($ app [AuthorizationService::class]);
152
142
$ service ->addParameterMiddleware ($ app [ValidateFieldMiddleware::class]);
153
-
154
143
$ service ->addTypeMapperFactory ($ app [PaginatorTypeMapperFactory::class]);
155
144
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 ];
159
148
}
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 ];
163
156
}
164
- foreach ($ controllers as $ namespace ) {
157
+ foreach ($ mutations as $ namespace ) {
165
158
$ service ->addControllerNamespace ($ namespace );
166
159
}
160
+
161
+ $ types = config ('graphqlite.types ' , 'App \\GraphQL \\Types ' );
162
+ if (!is_iterable ($ types )) {
163
+ $ types = [ $ types ];
164
+ }
167
165
foreach ($ types as $ namespace ) {
168
166
$ service ->addTypeNamespace ($ namespace );
169
167
}
@@ -181,14 +179,11 @@ public function register()
181
179
182
180
return $ schemaFactory ->createSchema ();
183
181
});
182
+
183
+ DocumentValidator::addRule (new DisableIntrospection (config ('graphqlite.disable_introspection ' , false )));
184
184
}
185
185
186
- /**
187
- * Get the services provided by the provider.
188
- *
189
- * @return array
190
- */
191
- public function provides ()
186
+ public function provides (): array
192
187
{
193
188
return [
194
189
SchemaFactory::class,
0 commit comments