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/June2018/#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
Borrow the value, returns None
if the value is undefined
or null
, otherwise returns Some(T)
.
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.
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
Qualified typename.
Create type information in the registry and return qualified typename.
Introspection type name 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
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