Expose executor.location(), rename executor.push_error() to

`executor.push_error_at()` and add a new `executor.push_error()`
This commit is contained in:
rushmorem 2017-08-13 16:52:34 +02:00 committed by Magnus Hallin
parent b3ea59cd3b
commit f7625056ac
2 changed files with 16 additions and 6 deletions

View file

@ -288,8 +288,7 @@ impl<'a, CtxT> Executor<'a, CtxT> {
match self.resolve(info, value) {
Ok(v) => v,
Err(e) => {
let position = self.field_path.location().clone();
self.push_error(e, position);
self.push_error(e);
Value::null()
}
}
@ -355,8 +354,19 @@ impl<'a, CtxT> Executor<'a, CtxT> {
self.fragments.get(name).map(|f| *f)
}
/// Add an error to the execution engine
pub fn push_error(&self, error: FieldError, location: SourcePosition) {
/// The current location of the executor
pub fn location(&self) -> &SourcePosition {
self.field_path.location()
}
/// Add an error to the execution engine at the current executor location
pub fn push_error(&self, error: FieldError) {
let location = self.location().clone();
self.push_error_at(error, location);
}
/// Add an error to the execution engine at a specific location
pub fn push_error_at(&self, error: FieldError, location: SourcePosition) {
let mut path = Vec::new();
self.field_path.construct_path(&mut path);

View file

@ -390,7 +390,7 @@ fn resolve_selection_set_into<T, CtxT>(
match field_result {
Ok(v) => merge_key_into(result, response_name, v),
Err(e) => {
sub_exec.push_error(e, start_pos.clone());
sub_exec.push_error_at(e, start_pos.clone());
result.insert((*response_name).to_owned(), Value::null());
}
}
@ -439,7 +439,7 @@ fn resolve_selection_set_into<T, CtxT>(
result.insert(k, v);
}
} else if let Err(e) = sub_result {
sub_exec.push_error(e, start_pos.clone());
sub_exec.push_error_at(e, start_pos.clone());
}
} else {
resolve_selection_set_into(