Skip to content

Expose current executor's location #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions juniper/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions juniper/src/types/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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(
Expand Down