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
DataFetchersDelegate
s (see DataFetchersDelegate
doc for more information on
that).- Author:
- etienne-sf
-
Method Summary
Modifier and TypeMethodDescriptionThe name of the DataFetcher, in camelCase.Retrieves theDataFetchersDelegate
in which this Data Fetcher is implementedgetField()
Retrieves theField
that 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
:DataFetcher
for fields of object, interface(...).default String
The 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.boolean
Returns true if this DataFetcher should be annotated with the@BatchMapping
annotation.boolean
Returns 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 theField
that this data fetcher fills. The arguments for the data fetcher are the arguments of its field.- Returns:
-
getDataFetchersDelegate
DataFetchersDelegate getDataFetchersDelegate()Retrieves theDataFetchersDelegate
in 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
:DataFetcher
for fields of object, interface(...). TheseDataFetcher
need 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.DataFetcher
for query/mutation/subscription. In these case, the field that is fetched by thisDataFetcher
has 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@BatchMapping
annotation. This is controlled by thegenerateBatchMappingDataFetchers
plugin 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:
-