Package graphql.execution
Class DataFetcherResult<T>
- java.lang.Object
-
- graphql.execution.DataFetcherResult<T>
-
- Type Parameters:
T
- The type of the data fetched
@PublicApi public class DataFetcherResult<T> extends java.lang.Object
An object that can be returned from aDataFetcher
that contains both data, local context and errors to be relativized and added to the final result. This is a useful when your ``DataFetcher`` retrieves data from multiple sources or from another GraphQL resource or you want to pass extra context to lower levels. This also allows you to pass down new local context objects between parent and child fields. If you return agetLocalContext()
value then it will be passed down into any child fields viaDataFetchingEnvironment.getLocalContext()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DataFetcherResult.Builder<T>
-
Constructor Summary
Constructors Constructor Description DataFetcherResult(T data, java.util.List<GraphQLError> errors)
Deprecated.use thenewResult()
builder instead
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description T
getData()
java.util.List<GraphQLError>
getErrors()
java.lang.Object
getLocalContext()
A data fetcher result can supply a context object for that field that is passed down to child fieldsboolean
hasErrors()
static <T> DataFetcherResult.Builder<T>
newResult()
Creates a new data fetcher result builderDataFetcherResult<T>
transform(java.util.function.Consumer<DataFetcherResult.Builder<T>> builderConsumer)
This helps you transform the current DataFetcherResult into another one by starting a builder with all the current values and allows you to transform it how you want.
-
-
-
Constructor Detail
-
DataFetcherResult
@Deprecated public DataFetcherResult(T data, java.util.List<GraphQLError> errors)
Deprecated.use thenewResult()
builder insteadCreates a data fetcher result- Parameters:
data
- the dataerrors
- the errors
-
-
Method Detail
-
getData
public T getData()
- Returns:
- The data fetched. May be null.
-
getErrors
public java.util.List<GraphQLError> getErrors()
- Returns:
- errors encountered when fetching data. This will be non null but possibly empty.
-
hasErrors
public boolean hasErrors()
- Returns:
- true if there are any errors present
-
getLocalContext
public java.lang.Object getLocalContext()
A data fetcher result can supply a context object for that field that is passed down to child fields- Returns:
- a local context object
-
transform
public DataFetcherResult<T> transform(java.util.function.Consumer<DataFetcherResult.Builder<T>> builderConsumer)
This helps you transform the current DataFetcherResult into another one by starting a builder with all the current values and allows you to transform it how you want.- Parameters:
builderConsumer
- the consumer code that will be given a builder to transform- Returns:
- a new instance produced by calling
build
on that builder
-
newResult
public static <T> DataFetcherResult.Builder<T> newResult()
Creates a new data fetcher result builder- Type Parameters:
T
- the type of the result- Returns:
- a new builder
-
-