Skip to content

Commit 62bb749

Browse files
committed
Made it generic
1 parent 33e26e1 commit 62bb749

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/main/java/graphql/annotations/MethodDataFetcher.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import static graphql.annotations.ReflectionKit.newInstance;
3131
import static graphql.annotations.util.NamingKit.toGraphqlName;
3232

33-
class MethodDataFetcher implements DataFetcher {
33+
public class MethodDataFetcher<T> implements DataFetcher<T> {
3434
private final Method method;
3535
private final TypeFunction typeFunction;
3636

@@ -44,23 +44,23 @@ public MethodDataFetcher(Method method, TypeFunction typeFunction) {
4444
}
4545

4646
@Override
47-
public Object get(DataFetchingEnvironment environment) {
47+
public T get(DataFetchingEnvironment environment) {
4848
try {
49-
Object obj;
49+
T obj;
5050

5151
if (Modifier.isStatic(method.getModifiers())) {
5252
obj = null;
5353
} else if (method.getAnnotation(GraphQLInvokeDetached.class) != null) {
54-
obj = newInstance(method.getDeclaringClass());
54+
obj = newInstance((Class<T>) method.getDeclaringClass());
5555
} else if (!method.getDeclaringClass().isInstance(environment.getSource())) {
56-
obj = newInstance(method.getDeclaringClass(), environment.getSource());
56+
obj = newInstance((Class<T>) method.getDeclaringClass(), environment.getSource());
5757
} else {
5858
obj = environment.getSource();
5959
if (obj == null) {
6060
return null;
6161
}
6262
}
63-
return method.invoke(obj, invocationArgs(environment));
63+
return (T) method.invoke(obj, invocationArgs(environment));
6464
} catch (IllegalAccessException | InvocationTargetException e) {
6565
throw new RuntimeException(e);
6666
}

0 commit comments

Comments
 (0)