Class DataFetchersDelegateHumanImpl
java.lang.Object
org.starwars.server.datafetchersdelegate.DataFetchersDelegateHumanImpl
- All Implemented Interfaces:
DataFetchersDelegateHuman
@Component
public class DataFetchersDelegateHumanImpl
extends Object
implements DataFetchersDelegateHuman
- Author:
- etienne-sf
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionThis method loads the data for Human.appearsIn.batchLoader
(List<UUID> keys) This method loads a list of ${dataFetcher.field.name}, based on the list of id to be fetched.This method loads the data for Human.friends.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.starwars.server.util.DataFetchersDelegateHuman
unorderedReturnBatchLoader
-
Field Details
-
logger
protected org.slf4j.Logger loggerThe logger for this instance
-
-
Constructor Details
-
DataFetchersDelegateHumanImpl
public DataFetchersDelegateHumanImpl()
-
-
Method Details
-
friends
Description copied from interface:DataFetchersDelegateHuman
This method loads the data for Human.friends. It may return whatever is accepted by the Spring Controller, that is:- A resolved value of any type (typically, a List<org.starwars.server.Character>)
- Mono and Flux for asynchronous value(s). Supported for controller methods and for any DataFetcher as described in Reactive DataFetcher. This would typically be a Mono<List<org.starwars.server.Character>> or a Flux<List<org.starwars.server.Character>>
- Kotlin coroutine and Flow are adapted to Mono and Flux
- java.util.concurrent.Callable to have the value(s) produced asynchronously. For this to work, AnnotatedControllerConfigurer must be configured with an Executor. This would typically by a Callable<List<org.starwars.server.Character>>
- A CompletableFuture<?>, for instance CompletableFuture<List<org.starwars.server.Character>>. This allows to use graphql-java java-dataloader to highly optimize the number of requests to the server. The principle is this one: The data loader collects all the data to load, avoid to load several times the same data, and allows parallel execution of the queries, if multiple queries are to be run.
- A Publisher (instead of a Flux), for Subscription for instance
- Specified by:
friends
in interfaceDataFetchersDelegateHuman
- Parameters:
environment
- The GraphQLDataFetchingEnvironment
. It gives you access to the full GraphQL context for this DataFetchersource
- The object from which the field is fetch. In other word: the aim of this data fetcher is to fetch the friends attribute of the origin, which is an instance of {ObjectType {name:Human, fields:{Field{name:id, type:ID!, params:[]},Field{name:name, type:String!, params:[]},Field{name:friends, type:[Character], params:[]},Field{name:appearsIn, type:[Episode]!, params:[]},Field{name:homePlanet, type:String, params:[]}}, implements Character, comments ""}. It depends on your data modle, but it typically contains the id to use in the query.
-
appearsIn
public List<Episode> appearsIn(graphql.schema.DataFetchingEnvironment dataFetchingEnvironment, Human source) Description copied from interface:DataFetchersDelegateHuman
This method loads the data for Human.appearsIn. It may return whatever is accepted by the Spring Controller, that is:- A resolved value of any type (typically, a List<org.starwars.server.Episode>)
- Mono and Flux for asynchronous value(s). Supported for controller methods and for any DataFetcher as described in Reactive DataFetcher. This would typically be a Mono<List<org.starwars.server.Episode>> or a Flux<List<org.starwars.server.Episode>>
- Kotlin coroutine and Flow are adapted to Mono and Flux
- java.util.concurrent.Callable to have the value(s) produced asynchronously. For this to work, AnnotatedControllerConfigurer must be configured with an Executor. This would typically by a Callable<List<org.starwars.server.Episode>>
- A CompletableFuture<?>, for instance CompletableFuture<List<org.starwars.server.Episode>>. This allows to use graphql-java java-dataloader to highly optimize the number of requests to the server. The principle is this one: The data loader collects all the data to load, avoid to load several times the same data, and allows parallel execution of the queries, if multiple queries are to be run.
- A Publisher (instead of a Flux), for Subscription for instance
- Specified by:
appearsIn
in interfaceDataFetchersDelegateHuman
- Parameters:
dataFetchingEnvironment
- The GraphQLDataFetchingEnvironment
. It gives you access to the full GraphQL context for this DataFetchersource
- The object from which the field is fetch. In other word: the aim of this data fetcher is to fetch the appearsIn attribute of the origin, which is an instance of {ObjectType {name:Human, fields:{Field{name:id, type:ID!, params:[]},Field{name:name, type:String!, params:[]},Field{name:friends, type:[Character], params:[]},Field{name:appearsIn, type:[Episode]!, params:[]},Field{name:homePlanet, type:String, params:[]}}, implements Character, comments ""}. It depends on your data modle, but it typically contains the id to use in the query.
-
batchLoader
Description copied from interface:DataFetchersDelegateHuman
This method loads a list of ${dataFetcher.field.name}, based on the list of id to be fetched. This method is used by graphql-java java-dataloader to highly optimize the number of requests to the server, when recursing down through the object associations.
You can find more information on this page: graphql-java batching
Important notes:- The list returned by this method must be sorted in the exact same order as the given keys list. If values are missing (no value for a given key), then the returned list must contain a null value at this key's position.
- One of
batchLoader
orunorderedReturnBatchLoader
must be overriden in the data fetcher implementation. If not, then a NullPointerException will be thrown at runtime, with a proper error message. - If your data storage implementation makes it complex to return values in the same order as the keys list, then it's
easier to override
unorderedReturnBatchLoader
, and let the default implementation ofbatchLoader
order the values
- Specified by:
batchLoader
in interfaceDataFetchersDelegateHuman
- Parameters:
keys
- A list of ID's id, for which the matching objects must be returned- Returns:
- A list of IDs
-