@PublicApi public class PropertyDataFetcher<T> extends java.lang.Object implements DataFetcher<T>, TrivialDataFetcher<T>
DataFetcher
Constructor and Description |
---|
PropertyDataFetcher(java.lang.String propertyName)
This constructor will use the property name and examine the
DataFetchingEnvironment.getSource()
object for a getter method or field with that name. |
Modifier and Type | Method and Description |
---|---|
static void |
clearReflectionCache()
PropertyDataFetcher caches the methods and fields that map from a class to a property for runtime performance reasons.
|
static <T,O> PropertyDataFetcher<T> |
fetching(java.util.function.Function<O,T> function)
Returns a data fetcher that will present the
DataFetchingEnvironment.getSource() object to the supplied
function to obtain a value, which allows you to use Java 8 method references say obtain values in a
more type safe way. |
static <T> PropertyDataFetcher<T> |
fetching(java.lang.String propertyName)
Returns a data fetcher that will use the property name to examine the
DataFetchingEnvironment.getSource() object
for a getter method or field with that name, or if its a map, it will look up a value using
property name as a key. |
T |
get(DataFetchingEnvironment environment)
This is called by the graphql engine to fetch the value.
|
java.lang.String |
getPropertyName() |
static boolean |
setUseSetAccessible(boolean flag)
This can be used to control whether PropertyDataFetcher will use
AccessibleObject.setAccessible(boolean) to gain access to property
values. |
public PropertyDataFetcher(java.lang.String propertyName)
DataFetchingEnvironment.getSource()
object for a getter method or field with that name.propertyName
- the name of the property to retrievepublic static <T> PropertyDataFetcher<T> fetching(java.lang.String propertyName)
DataFetchingEnvironment.getSource()
object
for a getter method or field with that name, or if its a map, it will look up a value using
property name as a key.
For example :
DataFetcher functionDataFetcher = fetching("pojoPropertyName");
T
- the type of resultpropertyName
- the name of the property to retrievepublic static <T,O> PropertyDataFetcher<T> fetching(java.util.function.Function<O,T> function)
DataFetchingEnvironment.getSource()
object to the supplied
function to obtain a value, which allows you to use Java 8 method references say obtain values in a
more type safe way.
For example :
DataFetcher functionDataFetcher = fetching(Thing::getId);
O
- the type of the source objectT
- the type of resultfunction
- the function to use to obtain a value from the source objectpublic java.lang.String getPropertyName()
public T get(DataFetchingEnvironment environment)
DataFetcher
DataFetchingEnvironment
is a composite
context object that tells you all you need to know about who to fetch a data value in graphql type terms.get
in interface DataFetcher<T>
environment
- this is the data fetching environment which contains all the context you need to fetch a valueDataFetcherResult
public static void clearReflectionCache()
public static boolean setUseSetAccessible(boolean flag)
AccessibleObject.setAccessible(boolean)
to gain access to property
values. By default it PropertyDataFetcher WILL use setAccessible.flag
- whether to use setAccessible