Interface DataFetcher
- All Known Implementing Classes:
DataFetcherImpl
public interface DataFetcher
This class represents a GraphQL Data Fetcher. It's a piece of code that reads non scalar fields on GraphQL objects,
which includes: all fields for queries, mutations and subscriptions, and all non scalar fields for regular GraphQL
objects.
They are grouped into
They are grouped into
DataFetchersDelegates (see DataFetchersDelegate doc for more information on
that).- Author:
- etienne-sf
-
Method Summary
Modifier and TypeMethodDescriptionThe name of the DataFetcher, in camelCase.Retrieves theDataFetchersDelegatein which this Data Fetcher is implementedgetField()Retrieves theFieldthat this data fetcher fills.Retrieves the origin of thisDataFetcher, that is: the name of the object which contains the fields to fetch.
There are two kinds ofDataFetcher:DataFetcherfor fields of object, interface(...).default StringThe name of the DataFetcher, as it can be used in the Java code.getName()The name of the DataFetcher: it's actually the field name, as read in the GraphQL schema.The name of the DataFetcher, in PascalCase.booleanReturns true if this DataFetcher should be annotated with the@BatchMappingannotation.booleanReturns true if this DataFetcher needs a graphql-java java-dataloader to optimize the accesses to the database.
-
Method Details
-
getName
String getName()The name of the DataFetcher: it's actually the field name, as read in the GraphQL schema. This name is a valid java classname identifier, and is the name to use as a method name. For instance, for the field human.friends, the DataFetcher name is Human.- Returns:
-
getJavaName
The name of the DataFetcher, as it can be used in the Java code. If the name is a java keyword (class, default, break...), the java name it prefixed by an underscore.- Returns:
- The name of the DataFetcher, as it can be used in Java code
-
getCamelCaseName
String getCamelCaseName()The name of the DataFetcher, in camelCase.- Returns:
- See Also:
-
getPascalCaseName
String getPascalCaseName()The name of the DataFetcher, in PascalCase.- Returns:
- See Also:
-
getField
Field getField()Retrieves theFieldthat this data fetcher fills. The arguments for the data fetcher are the arguments of its field.- Returns:
-
getDataFetchersDelegate
DataFetchersDelegate getDataFetchersDelegate()Retrieves theDataFetchersDelegatein which this Data Fetcher is implemented- Returns:
-
getGraphQLOriginType
Type getGraphQLOriginType()Retrieves the origin of thisDataFetcher, that is: the name of the object which contains the fields to fetch.
There are two kinds ofDataFetcher:DataFetcherfor fields of object, interface(...). TheseDataFetcherneed to have access to the object instance, that contains the field (or attribute) it fetches. This instance is the origin, and will be a parameter in the DataFetcher call, that contains the instance of the object, for which this field is fetched.DataFetcherfor query/mutation/subscription. In these case, the field that is fetched by thisDataFetcherhas no origin: it's the start of the request. To check that, you must check the owningDataFetchersDelegate, its type, then check the request type.
- Returns:
- the GraphQL name of the type that contains this field, or null if this is a request ()
-
isBatchMapping
boolean isBatchMapping()Returns true if this DataFetcher should be annotated with the@BatchMappingannotation. This is controlled by thegenerateBatchMappingDataFetchersplugin parameter- Returns:
-
isWithDataLoader
boolean isWithDataLoader()Returns true if this DataFetcher needs a graphql-java java-dataloader to optimize the accesses to the database.
For instance, the DataDetcher would return CompletableFuture<List> (if completableFuture is true) or List (if completableFuture is false).
This plugin behavior on this subject is controlled by the generateDataLoaderForLists plugin parameter and the generateDataLoaderForLists directive (that can associated directly to the GraphQL field)- Returns:
-