7
7
use Illuminate \Support \ServiceProvider ;
8
8
use LastDragon_ru \LaraASP \Core \Concerns \ProviderWithConfig ;
9
9
use LastDragon_ru \LaraASP \Core \Concerns \ProviderWithTranslations ;
10
+ use LastDragon_ru \LaraASP \GraphQL \Helpers \EnumHelper ;
10
11
use LastDragon_ru \LaraASP \GraphQL \SearchBy \Directive \SearchByDirective ;
11
12
use LastDragon_ru \LaraASP \GraphQL \SortBy \Directive \SortByDirective ;
12
13
use Nuwave \Lighthouse \Events \RegisterDirectiveNamespaces ;
14
+ use Nuwave \Lighthouse \Schema \TypeRegistry ;
13
15
14
16
use function array_slice ;
15
17
use function explode ;
16
18
use function implode ;
19
+ use function is_int ;
17
20
18
21
class Provider extends ServiceProvider {
19
22
use ProviderWithConfig;
@@ -23,6 +26,7 @@ public function boot(Dispatcher $dispatcher): void {
23
26
$ this ->bootConfig ([
24
27
'search_by.scalars ' ,
25
28
'search_by.aliases ' ,
29
+ 'enums ' ,
26
30
]);
27
31
$ this ->bootDirectives ($ dispatcher );
28
32
}
@@ -31,6 +35,7 @@ public function register(): void {
31
35
parent ::register ();
32
36
33
37
$ this ->registerDirectives ();
38
+ $ this ->registerEnums ();
34
39
}
35
40
36
41
protected function bootDirectives (Dispatcher $ dispatcher ): void {
@@ -60,6 +65,19 @@ protected function registerDirectives(): void {
60
65
});
61
66
}
62
67
68
+ protected function registerEnums (): void {
69
+ $ registry = $ this ->app ->make (TypeRegistry::class);
70
+ $ enums = (array ) $ this ->app ->make (Repository::class)->get ("{$ this ->getName ()}.enums " );
71
+
72
+ foreach ($ enums as $ name => $ enum ) {
73
+ if (is_int ($ name )) {
74
+ $ name = null ;
75
+ }
76
+
77
+ $ registry ->register (EnumHelper::getType ($ enum , $ name ));
78
+ }
79
+ }
80
+
63
81
protected function getName (): string {
64
82
return Package::Name;
65
83
}
0 commit comments