juniper::executor

Struct FieldError

Source
pub struct FieldError<S = DefaultScalarValue> { /* private fields */ }
Expand description

Error type for errors that occur during field resolution

Field errors are represented by a human-readable error message and an optional Value structure containing additional information.

They can be converted to from any type that implements std::fmt::Display, which makes error chaining with the ? operator a breeze:

fn get_string(data: Vec<u8>) -> Result<String, FieldError>
{
    let s = String::from_utf8(data)?;
    Ok(s)
}

Implementations§

Source§

impl<S> FieldError<S>

Source

pub fn new<T: Display>(e: T, extensions: Value<S>) -> Self

Construct a new FieldError with additional data.

You can use the graphql_value! macro for construction:

use juniper::{graphql_value, FieldError};

FieldError::new(
    "Could not open connection to the database",
    graphql_value!({"internal_error": "Connection refused"}),
);

The extensions parameter will be added to the "extensions" field of the "errors" object in response:

{
  "errors": [
    "message": "Could not open connection to the database",
    "locations": [{"line": 2, "column": 4}],
    "extensions": {
      "internal_error": "Connection refused"
    }
  ]
}

If the argument is Value::Null, then no extra data will be included.

Source

pub fn message(&self) -> &str

Returns "message" field of this FieldError.

Source

pub fn extensions(&self) -> &Value<S>

Returns "extensions" field of this FieldError.

If there is no "extensions", then Value::Null will be returned.

Source

pub fn map_scalar_value<Into>(self) -> FieldError<Into>
where S: ScalarValue, Into: ScalarValue,

Maps the ScalarValue type of this FieldError into the specified one.

Source

pub fn map_message(self, f: impl FnOnce(String) -> String) -> Self

Maps the FieldError::message with the given function.

Trait Implementations§

Source§

impl<S: Clone> Clone for FieldError<S>

Source§

fn clone(&self) -> FieldError<S>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: Debug> Debug for FieldError<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Display, S> From<T> for FieldError<S>

Source§

fn from(e: T) -> Self

Converts to this type from the input type.
Source§

impl<S1: ScalarValue, S2: ScalarValue> IntoFieldError<S2> for FieldError<S1>

Source§

fn into_field_error(self) -> FieldError<S2>

Performs the custom conversion into a FieldError.
Source§

impl<S: PartialEq> PartialEq for FieldError<S>

Source§

fn eq(&self, other: &FieldError<S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S> StructuralPartialEq for FieldError<S>

Auto Trait Implementations§

§

impl<S> Freeze for FieldError<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for FieldError<S>
where S: RefUnwindSafe,

§

impl<S> Send for FieldError<S>
where S: Send,

§

impl<S> Sync for FieldError<S>
where S: Sync,

§

impl<S> Unpin for FieldError<S>
where S: Unpin,

§

impl<S> UnwindSafe for FieldError<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.