Package graphql.execution
Class DataFetcherResult<T>
java.lang.Object
graphql.execution.DataFetcherResult<T>
- Type Parameters:
T
- The type of the data fetched
An object that can be returned from a
DataFetcher
that contains both data, local context and errors to be 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()
You can also have DataFetcher
s contribute to the ExecutionResult.getExtensions()
by returning
extensions maps that will be merged together via the ExtensionsBuilder
and its ExtensionsMerger
in place.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final T
private final List
<GraphQLError> private final Object
-
Constructor Summary
ConstructorsModifierConstructorDescriptionDataFetcherResult
(T data, List<GraphQLError> errors) Deprecated.private
DataFetcherResult
(T data, List<GraphQLError> errors, Object localContext, Map<Object, Object> extensions) -
Method Summary
Modifier and TypeMethodDescriptiongetData()
A data fetcher result can supply extension values that will be merged into the result via theExtensionsBuilder
at the end of the operation.A data fetcher result can supply a context object for that field that is passed down to child fieldsboolean
<R> DataFetcherResult
<R> Transforms the data of the current DataFetcherResult using the provided function.static <T> DataFetcherResult.Builder
<T> Creates a new data fetcher result buildertransform
(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.
-
Field Details
-
data
-
errors
-
localContext
-
extensions
-
-
Constructor Details
-
DataFetcherResult
Deprecated.use thenewResult()
builder insteadCreates a data fetcher result- Parameters:
data
- the dataerrors
- the errors
-
DataFetcherResult
-
-
Method Details
-
getData
- Returns:
- The data fetched. May be null.
-
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
A data fetcher result can supply a context object for that field that is passed down to child fields- Returns:
- a local context object
-
getExtensions
A data fetcher result can supply extension values that will be merged into the result via theExtensionsBuilder
at the end of the operation.The
ExtensionsMerger
in place inside theExtensionsBuilder
will control how these extension values get merged.- Returns:
- a map of extension values to be merged
- See Also:
-
transform
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
-
map
Transforms the data of the current DataFetcherResult using the provided function. All other values are left unmodified.- Type Parameters:
R
- the result type- Parameters:
transformation
- the transformation that should be applied to the data- Returns:
- a new instance with where the data value has been transformed
-
newResult
Creates a new data fetcher result builder- Type Parameters:
T
- the type of the result- Returns:
- a new builder
-
newResult()
builder instead