graphql.execution.incremental.DeferredCallContext Maven / Gradle / Ivy
package graphql.execution.incremental;
import graphql.ExceptionWhileDataFetching;
import graphql.GraphQLError;
import graphql.Internal;
import graphql.execution.ResultPath;
import graphql.language.SourceLocation;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* Contains data relevant to the execution of a {@link DeferredFragmentCall}.
*
* The responsibilities of this class are similar to {@link graphql.execution.ExecutionContext}, but restricted to the
* execution of a deferred call (instead of the whole GraphQL execution like {@link graphql.execution.ExecutionContext}).
*
* Some behaviours, like error capturing, need to be scoped to a single {@link DeferredFragmentCall}, because each defer payload
* contains its own distinct list of errors.
*/
@Internal
public class DeferredCallContext {
private final List errors = new CopyOnWriteArrayList<>();
public void onFetchingException(ResultPath path, SourceLocation sourceLocation, Throwable throwable) {
ExceptionWhileDataFetching error = new ExceptionWhileDataFetching(path, throwable, sourceLocation);
onError(error);
}
public void onError(GraphQLError graphqlError) {
errors.add(graphqlError);
}
/**
* @return a list of errors that were encountered while executing this deferred call
*/
public List getErrors() {
return errors;
}
}