Package graphql.schema.fetching
Class LambdaFetchingSupport
- java.lang.Object
-
- graphql.schema.fetching.LambdaFetchingSupport
-
public class LambdaFetchingSupport extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description LambdaFetchingSupport()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.reflect.Method
checkForSingleParameterPeer(java.lang.reflect.Method candidateMethod, java.util.List<java.lang.reflect.Method> allMethods)
static java.util.Optional<java.util.function.Function<java.lang.Object,java.lang.Object>>
createGetter(java.lang.Class<?> sourceClass, java.lang.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 java.lang.String
decapitalize(java.lang.String name)
private static java.lang.reflect.Method
findBestBooleanGetter(java.util.List<java.lang.reflect.Method> methods)
private static java.util.List<java.lang.reflect.Method>
findMethodsForProperty(java.lang.Class<?> sourceClass, java.util.function.Predicate<java.lang.reflect.Method> predicate)
Finds all methods in a class hierarchy that match the property name - they might not be suitable but theyprivate static java.lang.reflect.Method
getCandidateMethod(java.lang.Class<?> sourceClass, java.lang.String propertyName)
private static java.lang.invoke.MethodHandles.Lookup
getLookup(java.lang.Class<?> targetClass)
private static boolean
hasNoParameters(java.lang.reflect.Method method)
private static boolean
isBooleanGetter(java.lang.reflect.Method method)
private static boolean
isGetterNamed(java.lang.reflect.Method method)
private static boolean
isObjectMethod(java.lang.reflect.Method method)
private static boolean
isPossiblePojoMethod(java.lang.reflect.Method method)
private static boolean
isPublic(java.lang.reflect.Method method)
private static boolean
isRecordLike(java.lang.reflect.Method method)
(package private) static java.util.function.Function<java.lang.Object,java.lang.Object>
mkCallFunction(java.lang.Class<?> targetClass, java.lang.String targetMethod, java.lang.Class<?> targetMethodReturnType)
private static java.lang.String
mkPropertyNameGetter(java.lang.reflect.Method method)
private static boolean
returnsSomething(java.lang.reflect.Method method)
-
-
-
Method Detail
-
createGetter
public static java.util.Optional<java.util.function.Function<java.lang.Object,java.lang.Object>> createGetter(java.lang.Class<?> sourceClass, java.lang.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
private static java.lang.reflect.Method getCandidateMethod(java.lang.Class<?> sourceClass, java.lang.String propertyName)
-
checkForSingleParameterPeer
private static java.lang.reflect.Method checkForSingleParameterPeer(java.lang.reflect.Method candidateMethod, java.util.List<java.lang.reflect.Method> allMethods)
-
findBestBooleanGetter
private static java.lang.reflect.Method findBestBooleanGetter(java.util.List<java.lang.reflect.Method> methods)
-
findMethodsForProperty
private static java.util.List<java.lang.reflect.Method> findMethodsForProperty(java.lang.Class<?> sourceClass, java.util.function.Predicate<java.lang.reflect.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
private static boolean isPossiblePojoMethod(java.lang.reflect.Method method)
-
isRecordLike
private static boolean isRecordLike(java.lang.reflect.Method method)
-
isBooleanGetter
private static boolean isBooleanGetter(java.lang.reflect.Method method)
-
hasNoParameters
private static boolean hasNoParameters(java.lang.reflect.Method method)
-
isGetterNamed
private static boolean isGetterNamed(java.lang.reflect.Method method)
-
returnsSomething
private static boolean returnsSomething(java.lang.reflect.Method method)
-
isPublic
private static boolean isPublic(java.lang.reflect.Method method)
-
isObjectMethod
private static boolean isObjectMethod(java.lang.reflect.Method method)
-
mkPropertyNameGetter
private static java.lang.String mkPropertyNameGetter(java.lang.reflect.Method method)
-
decapitalize
private static java.lang.String decapitalize(java.lang.String name)
-
mkCallFunction
static java.util.function.Function<java.lang.Object,java.lang.Object> mkCallFunction(java.lang.Class<?> targetClass, java.lang.String targetMethod, java.lang.Class<?> targetMethodReturnType) throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
getLookup
private static java.lang.invoke.MethodHandles.Lookup getLookup(java.lang.Class<?> targetClass)
-
-