Enum async_graphql::types::MaybeUndefined [−][src]
pub enum MaybeUndefined<T> {
Undefined,
Null,
Value(T),
}Expand description
Similar to Option, but it has three states, undefined, null and x.
Reference: https://spec.graphql.org/October2021/#sec-Null-Value
Examples
use async_graphql::*;
struct Query;
#[Object]
impl Query {
async fn value1(&self, input: MaybeUndefined<i32>) -> i32 {
if input.is_null() {
1
} else if input.is_undefined() {
2
} else {
input.take().unwrap()
}
}
}
tokio::runtime::Runtime::new().unwrap().block_on(async {
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
let query = r#"
{
v1:value1(input: 99)
v2:value1(input: null)
v3:value1
}"#;
assert_eq!(
schema.execute(query).await.into_result().unwrap().data,
value!({
"v1": 99,
"v2": 1,
"v3": 2,
})
);
});Variants
Implementations
Returns true if the MaybeUndefined<T> is undefined.
Borrow the value, returns None if the the MaybeUndefined<T> is undefined or null, otherwise returns Some(T).
Converts the MaybeUndefined<T> to Option<Option<T>>.
Converts the MaybeUndefined<T> to Option<Option<&U>>.
Returns true if the MaybeUndefined<T> contains the given value.
Returns true if the MaybeUndefined<T> contains the given nullable value.
Maps a MaybeUndefined<T> to MaybeUndefined<U> by applying a function to the contained nullable value
Maps a MaybeUndefined<T> to MaybeUndefined<U> by applying a function to the contained value
Transposes a MaybeUndefined of a Result into a Result of a MaybeUndefined.
MaybeUndefined::Undefined will be mapped to Ok(MaybeUndefined::Undefined).
MaybeUndefined::Null will be mapped to Ok(MaybeUndefined::Null).
MaybeUndefined::Value(Ok(_)) and MaybeUndefined::Value(Err(_)) will be mapped to
Ok(MaybeUndefined::Value(_)) and Err(_).
Trait Implementations
fn deserialize<D>(deserializer: D) -> Result<MaybeUndefined<T>, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<MaybeUndefined<T>, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Performs the conversion.
type RawValueType = T::RawValueType
type RawValueType = T::RawValueType
The raw type used for validator. Read more
Qualified typename.
Create type information in the registry and return qualified typename.
Parse from Value. None represents undefined.
Returns a reference to the raw value.
This method tests for self and other values to be equal, and is used
by ==. Read more
This method tests for !=.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for MaybeUndefined<T> where
T: RefUnwindSafe,
impl<T> Send for MaybeUndefined<T> where
T: Send,
impl<T> Sync for MaybeUndefined<T> where
T: Sync,
impl<T> Unpin for MaybeUndefined<T> where
T: Unpin,
impl<T> UnwindSafe for MaybeUndefined<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.
Instruments this type with the provided Span, returning an
Instrumented wrapper. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more