15
15
*/
16
16
package org .springframework .graphql .data .method ;
17
17
18
- import java .lang .reflect .InvocationTargetException ;
19
- import java .lang .reflect .Method ;
20
18
import java .util .Arrays ;
21
19
22
20
import graphql .schema .DataFetchingEnvironment ;
23
21
24
- import org .springframework .core .CoroutinesUtils ;
25
22
import org .springframework .core .DefaultParameterNameDiscoverer ;
26
- import org .springframework .core .KotlinDetector ;
27
23
import org .springframework .core .MethodParameter ;
28
24
import org .springframework .core .ParameterNameDiscoverer ;
29
25
import org .springframework .lang .Nullable ;
30
26
import org .springframework .util .Assert ;
31
27
import org .springframework .util .ObjectUtils ;
32
- import org .springframework .util .ReflectionUtils ;
33
28
34
29
/**
35
- * Extension of {@link HandlerMethod} that can resolve method arguments from a
36
- * {@link DataFetchingEnvironment} and invoke the method.
30
+ * An extension of {@link HandlerMethod} for annotated handler methods adapted
31
+ * to {@link graphql.schema.DataFetcher} with {@link DataFetchingEnvironment}
32
+ * as their input.
37
33
*
38
34
* @author Rossen Stoyanchev
39
35
* @since 1.0.0
40
36
*/
41
- public class InvocableHandlerMethod extends HandlerMethod {
37
+ public class DataFetcherHandlerMethod extends InvocableHandlerMethodSupport {
42
38
43
39
private static final Object [] EMPTY_ARGS = new Object [0 ];
44
40
@@ -48,7 +44,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
48
44
private final ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer ();
49
45
50
46
51
- public InvocableHandlerMethod (HandlerMethod handlerMethod , HandlerMethodArgumentResolverComposite resolvers ) {
47
+ public DataFetcherHandlerMethod (HandlerMethod handlerMethod , HandlerMethodArgumentResolverComposite resolvers ) {
52
48
super (handlerMethod );
53
49
Assert .isTrue (!resolvers .getResolvers ().isEmpty (), "No argument resolvers" );
54
50
this .resolvers = resolvers ;
@@ -127,40 +123,4 @@ protected Object[] getMethodArgumentValues(
127
123
return args ;
128
124
}
129
125
130
- /**
131
- * Invoke the handler method with the given argument values.
132
- */
133
- @ Nullable
134
- protected Object doInvoke (Object ... args ) throws Exception {
135
- Method method = getBridgedMethod ();
136
- ReflectionUtils .makeAccessible (method );
137
- try {
138
- if (KotlinDetector .isSuspendingFunction (method )) {
139
- return CoroutinesUtils .invokeSuspendingFunction (method , getBean (), args );
140
- }
141
- return method .invoke (getBean (), args );
142
- }
143
- catch (IllegalArgumentException ex ) {
144
- assertTargetBean (method , getBean (), args );
145
- String text = (ex .getMessage () != null ? ex .getMessage () : "Illegal argument" );
146
- throw new IllegalStateException (formatInvokeError (text , args ), ex );
147
- }
148
- catch (InvocationTargetException ex ) {
149
- // Unwrap for DataFetcherExceptionResolvers ...
150
- Throwable targetException = ex .getTargetException ();
151
- if (targetException instanceof RuntimeException ) {
152
- throw (RuntimeException ) targetException ;
153
- }
154
- else if (targetException instanceof Error ) {
155
- throw (Error ) targetException ;
156
- }
157
- else if (targetException instanceof Exception ) {
158
- throw (Exception ) targetException ;
159
- }
160
- else {
161
- throw new IllegalStateException (formatInvokeError ("Invocation failure" , args ), targetException );
162
- }
163
- }
164
- }
165
-
166
126
}
0 commit comments