File tree Expand file tree Collapse file tree 6 files changed +84
-2
lines changed Expand file tree Collapse file tree 6 files changed +84
-2
lines changed Original file line number Diff line number Diff line change @@ -160,3 +160,35 @@ For example:
160
160
*Note:*
161
161
- This event is dispatch by this bundle default error handler, that the reason why, disabling
162
162
error handler will also disable this event.
163
+
164
+ Type loaded
165
+ ----------------
166
+
167
+ *Event:* `graphql.type_loaded`
168
+
169
+ This event can be listen to modified type before schema registration.
170
+
171
+ For example :
172
+
173
+ ` ` ` yaml
174
+ App\E ventListener\T ypeDecorator:
175
+ tags:
176
+ - { name: kernel.event_listener, event: graphql.type_loaded, method: onTypeLoaded }
177
+ ` ` `
178
+
179
+ ` ` ` php
180
+ <?php
181
+
182
+ namespace App\E ventListener;
183
+
184
+ use Overblog\G raphQLBundle\E vent\T ypeLoadedEvent;
185
+
186
+ class TypeDecorator
187
+ {
188
+ public function onTypeLoaded(TypeLoadedEvent $event)
189
+ {
190
+ $type = $event->getType();
191
+ // here we can modified type
192
+ }
193
+ }
194
+ ` ` `
Original file line number Diff line number Diff line change @@ -10,4 +10,5 @@ final class Events
10
10
public const PRE_EXECUTOR = 'graphql.pre_executor ' ;
11
11
public const POST_EXECUTOR = 'graphql.post_executor ' ;
12
12
public const ERROR_FORMATTING = 'graphql.error_formatting ' ;
13
+ public const TYPE_LOADED = 'graphql.type_loaded ' ;
13
14
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Overblog \GraphQLBundle \Event ;
6
+
7
+ use GraphQL \Type \Definition \Type ;
8
+ use Symfony \Component \EventDispatcher \Event ;
9
+
10
+ final class TypeLoadedEvent extends Event
11
+ {
12
+ /** @var Type */
13
+ private $ type ;
14
+
15
+ public function __construct (Type $ type )
16
+ {
17
+ $ this ->type = $ type ;
18
+ }
19
+
20
+ public function getType (): Type
21
+ {
22
+ return $ this ->type ;
23
+ }
24
+ }
Original file line number Diff line number Diff line change @@ -81,6 +81,10 @@ public function getSolutionOptions(string $id)
81
81
return isset ($ this ->solutionOptions [$ id ]) ? $ this ->solutionOptions [$ id ] : [];
82
82
}
83
83
84
+ protected function onLoadSolution ($ solution ): void
85
+ {
86
+ }
87
+
84
88
/**
85
89
* @param string $id
86
90
*
@@ -97,10 +101,11 @@ private function loadSolution(string $id)
97
101
return $ this ->solutions [$ id ];
98
102
} else {
99
103
$ loader = $ this ->solutions [$ id ];
100
- $ this ->solutions [$ id ] = $ loader ();
104
+ $ this ->solutions [$ id ] = $ solution = $ loader ();
105
+ $ this ->onLoadSolution ($ solution );
101
106
$ this ->fullyLoadedSolutions [$ id ] = true ;
102
107
103
- return $ this -> solutions [ $ id ] ;
108
+ return $ solution ;
104
109
}
105
110
}
106
111
Original file line number Diff line number Diff line change 5
5
namespace Overblog \GraphQLBundle \Resolver ;
6
6
7
7
use GraphQL \Type \Definition \Type ;
8
+ use Overblog \GraphQLBundle \Event \Events ;
9
+ use Overblog \GraphQLBundle \Event \TypeLoadedEvent ;
10
+ use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
8
11
9
12
class TypeResolver extends AbstractResolver
10
13
{
11
14
private $ cache = [];
12
15
16
+ /** @var EventDispatcherInterface */
17
+ private $ dispatcher ;
18
+
19
+ public function setDispatcher (EventDispatcherInterface $ dispatcher ): void
20
+ {
21
+ $ this ->dispatcher = $ dispatcher ;
22
+ }
23
+
24
+ protected function onLoadSolution ($ solution ): void
25
+ {
26
+ if (null !== $ this ->dispatcher ) {
27
+ $ this ->dispatcher ->dispatch (Events::TYPE_LOADED , new TypeLoadedEvent ($ solution ));
28
+ }
29
+ }
30
+
13
31
/**
14
32
* @param string $alias
15
33
*
Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ services:
38
38
overblog_graphql.type_resolver :
39
39
class : Overblog\GraphQLBundle\Resolver\TypeResolver
40
40
public : true
41
+ calls :
42
+ - ['setDispatcher', ['@event_dispatcher']]
41
43
tags :
42
44
- { name: overblog_graphql.global_variable, alias: typeResolver }
43
45
You can’t perform that action at this time.
0 commit comments