Package graphql.schema.fetching
Class LambdaFetchingSupport
java.lang.Object
graphql.schema.fetching.LambdaFetchingSupport
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Method
checkForSingleParameterPeer
(Method candidateMethod, List<Method> allMethods) createGetter
(Class<?> sourceClass, String propertyName) This support class will useLambdaMetafactory
andMethodHandles
to create a dynamic function that allows access to a public getter method on the nominated class.private static String
decapitalize
(String name) private static Method
findBestBooleanGetter
(List<Method> methods) findMethodsForProperty
(Class<?> sourceClass, Predicate<Method> predicate) Finds all methods in a class hierarchy that match the property name - they might not be suitable but theyprivate static Method
getCandidateMethod
(Class<?> sourceClass, String propertyName) private static MethodHandles.Lookup
private static boolean
hasNoParameters
(Method method) private static boolean
isBooleanGetter
(Method method) private static boolean
isGetterNamed
(Method method) private static boolean
isObjectMethod
(Method method) private static boolean
isPossiblePojoMethod
(Method method) private static boolean
private static boolean
isRecordLike
(Method method) mkCallFunction
(Class<?> targetClass, String targetMethod, Class<?> targetMethodReturnType) private static String
mkPropertyNameGetter
(Method method) private static boolean
returnsSomething
(Method method)
-
Constructor Details
-
LambdaFetchingSupport
public LambdaFetchingSupport()
-
-
Method Details
-
createGetter
public static Optional<Function<Object,Object>> createGetter(Class<?> sourceClass, String propertyName) This support class will useLambdaMetafactory
andMethodHandles
to create a dynamic function that allows access to a public getter method on the nominated class.MethodHandles
is a caller senstive lookup mechanism. If the graphql-java cant lookup a class, then it won't be able to make dynamic lambda function to it.If one cant be made, because it doesn't exist or the calling class does not have access to the method, then it will return an empty result indicating that this strategy cant be used.
- Parameters:
sourceClass
- the class that has the property getter methodpropertyName
- the name of the property to get- Returns:
- a function that can be used to pass in an instance of source class and returns its getter method value
-
getCandidateMethod
-
checkForSingleParameterPeer
-
findBestBooleanGetter
-
findMethodsForProperty
private static List<Method> findMethodsForProperty(Class<?> sourceClass, Predicate<Method> predicate) Finds all methods in a class hierarchy that match the property name - they might not be suitable but they- Parameters:
sourceClass
- the class we are looking to work on- Returns:
- a list of getter methods for that property
-
isPossiblePojoMethod
-
isRecordLike
-
isBooleanGetter
-
hasNoParameters
-
isGetterNamed
-
returnsSomething
-
isPublic
-
isObjectMethod
-
mkPropertyNameGetter
-
decapitalize
-
mkCallFunction
static Function<Object,Object> mkCallFunction(Class<?> targetClass, String targetMethod, Class<?> targetMethodReturnType) throws Throwable - Throws:
Throwable
-
getLookup
-