1414 */
1515package graphql .annotations .dataFetchers ;
1616
17+ import graphql .annotations .annotationTypes .GraphQLBatched ;
1718import graphql .annotations .annotationTypes .GraphQLInvokeDetached ;
1819import graphql .annotations .annotationTypes .GraphQLName ;
1920import graphql .annotations .processor .ProcessingElementsContainer ;
@@ -45,10 +46,7 @@ public MethodDataFetcher(Method method, TypeFunction typeFunction, ProcessingEle
4546 public T get (DataFetchingEnvironment environment ) {
4647 try {
4748 T obj ;
48-
49- if (Modifier .isStatic (method .getModifiers ())) {
50- obj = null ;
51- } else if (method .getAnnotation (GraphQLInvokeDetached .class ) != null ) {
49+ if (method .isAnnotationPresent (GraphQLBatched .class ) || method .isAnnotationPresent (GraphQLInvokeDetached .class )) {
5250 obj = newInstance ((Class <T >) method .getDeclaringClass ());
5351 } else if (!method .getDeclaringClass ().isInstance (environment .getSource ())) {
5452 obj = newInstance ((Class <T >) method .getDeclaringClass (), environment .getSource ());
@@ -61,11 +59,11 @@ public T get(DataFetchingEnvironment environment) {
6159
6260 if (obj == null && environment .getSource () != null ) {
6361 Object value = getFieldValue (environment .getSource (), method .getName ());
64- if ( value != null ) return (T ) value ;
62+ return (T ) value ;
6563 }
6664
6765 return (T ) method .invoke (obj , invocationArgs (environment , container ));
68- } catch (IllegalAccessException | InvocationTargetException e ) {
66+ } catch (IllegalAccessException | InvocationTargetException | NoSuchFieldException e ) {
6967 throw new RuntimeException (e );
7068 }
7169 }
@@ -137,13 +135,9 @@ private Object buildArg(Type p, GraphQLType graphQLType, Object arg) {
137135 }
138136 }
139137
140- private Object getFieldValue (Object source , String fieldName ) throws IllegalAccessException {
141- try {
142- Field field = source .getClass ().getDeclaredField (fieldName );
143- field .setAccessible (true );
144- return field .get (source );
145- } catch (NoSuchFieldException e ) {
146- return null ;
147- }
138+ private Object getFieldValue (Object source , String fieldName ) throws IllegalAccessException , NoSuchFieldException {
139+ Field field = source .getClass ().getDeclaredField (fieldName );
140+ field .setAccessible (true );
141+ return field .get (source );
148142 }
149143}
0 commit comments