graphql.schema.PropertyDataFetcher Maven / Gradle / Ivy
package graphql.schema;
import graphql.Assert;
import graphql.PublicApi;
import graphql.TrivialDataFetcher;
import java.util.function.Function;
/**
* This is the default data fetcher used in graphql-java. It will examine
* maps and POJO java beans for values that match the desired name, typically the field name
* or it will use a provided function to obtain values.
* maps and POJO java beans for values that match the desired name.
*
* It uses the following strategies
*
* - If the source is null, return null
* - If the source is a Map, return map.get(propertyName)
* - If a function is provided, it is used
* - Find a public JavaBean getter method named `propertyName`
* - Find any getter method named `propertyName` and call method.setAccessible(true)
* - Find a public field named `propertyName`
* - Find any field named `propertyName` and call field.setAccessible(true)
* - If this cant find anything, then null is returned
*
*
* You can write your own data fetchers to get data from some other backing system
* if you need highly customised behaviour.
*
* @see graphql.schema.DataFetcher
*/
@PublicApi
public class PropertyDataFetcher implements DataFetcher, TrivialDataFetcher {
private final String propertyName;
private final Function