T
- The type of the data fetched@PublicApi public class DataFetcherResult<T> extends java.lang.Object
DataFetcher
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 a
getLocalContext()
value then it will be passed down into any child fields via
DataFetchingEnvironment.getLocalContext()
Modifier and Type | Class and Description |
---|---|
static class |
DataFetcherResult.Builder<T> |
Constructor and Description |
---|
DataFetcherResult(T data,
java.util.List<GraphQLError> errors)
Deprecated.
use the
newResult() builder instead |
Modifier and Type | Method and 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 fields
|
boolean |
hasErrors() |
boolean |
isMapRelativeErrors()
When this returns true, the data fetching code will map this error as being a relative error from the existing field.
|
static <T> DataFetcherResult.Builder<T> |
newResult()
Creates a new data fetcher result builder
|
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.
|
@Deprecated public DataFetcherResult(T data, java.util.List<GraphQLError> errors)
newResult()
builder insteaddata
- the dataerrors
- the errorspublic T getData()
public java.util.List<GraphQLError> getErrors()
public boolean hasErrors()
public java.lang.Object getLocalContext()
public boolean isMapRelativeErrors()
This is useful when you are calling a down stream graphql system and you want to make the errors appear to be from a point relative to the currently executing field.
By default this behavior is off
public DataFetcherResult<T> transform(java.util.function.Consumer<DataFetcherResult.Builder<T>> builderConsumer)
builderConsumer
- the consumer code that will be given a builder to transformbuild
on that builderpublic static <T> DataFetcherResult.Builder<T> newResult()
T
- the type of the result