11package graphql .schema ;
22
33
4- import graphql .Scalars ;
5-
64import java .lang .reflect .InvocationTargetException ;
75import java .lang .reflect .Method ;
86import java .util .Map ;
97
8+ import static graphql .Scalars .GraphQLBoolean ;
9+
1010public class PropertyDataFetcher implements DataFetcher {
1111
1212 private final String propertyName ;
@@ -22,11 +22,11 @@ public Object get(DataFetchingEnvironment environment) {
2222 if (source instanceof Map ) {
2323 return ((Map <?, ?>) source ).get (propertyName );
2424 }
25- return getPropertyViaGetter (source ,environment .getFieldType ());
25+ return getPropertyViaGetter (source , environment .getFieldType ());
2626 }
2727
2828 private Object getPropertyViaGetter (Object object , GraphQLOutputType outputType ) {
29- String prefix = outputType == Scalars . GraphQLBoolean ? "is" : "get" ;
29+ String prefix = isBooleanProperty ( outputType ) ? "is" : "get" ;
3030 String getterName = prefix + propertyName .substring (0 , 1 ).toUpperCase () + propertyName .substring (1 );
3131 try {
3232 Method method = object .getClass ().getMethod (getterName );
@@ -38,4 +38,12 @@ private Object getPropertyViaGetter(Object object, GraphQLOutputType outputType)
3838 throw new RuntimeException (e );
3939 }
4040 }
41+
42+ private boolean isBooleanProperty (GraphQLOutputType outputType ) {
43+ if (outputType == GraphQLBoolean ) return true ;
44+ if (outputType instanceof GraphQLNonNull ) {
45+ return ((GraphQLNonNull ) outputType ).getWrappedType () == GraphQLBoolean ;
46+ }
47+ return false ;
48+ }
4149}
0 commit comments