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

Undefined
Null
Value(T)

Implementations

Returns true if the MaybeUndefined is undefined.

Returns true if the MaybeUndefined is null.

Returns true if the MaybeUndefined is value.

Borrow the value, returns None if the value is undefined or null, otherwise returns Some(T).

Convert MaybeUndefined to Option.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Parse from Value. None represents undefined.

Convert to a Value for introspection.

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Type the name.

Qualified typename.

Create type information in the registry and return qualified typename.

Introspection type name Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Performs the conversion.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more

Attaches the current Context to this type, returning a WithContext wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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