pub struct FieldValue<'a>(_);
Available on crate feature dynamic-schema only.
Expand description

A value returned from the resolver function

Implementations

A null value equivalent to FieldValue::Value(Value::Null)

A none value equivalent to None::<FieldValue>

It is more convenient to use when your resolver needs to return None.

Examples
use async_graphql::dynamic::*;

let query =
    Object::new("Query").field(Field::new("value", TypeRef::named(TypeRef::INT), |ctx| {
        FieldFuture::new(async move { Ok(FieldValue::NONE) })
    }));

Returns a None::<FieldValue> meaning the resolver no results.

Create a FieldValue from Value

Create a FieldValue from owned any value

Create a FieldValue from owned any value

Create a FieldValue from list

Create a FieldValue and specify its type, which must be an object

NOTE: Fields of type Interface or Union must return FieldValue::WithType.

Examples
use async_graphql::{dynamic::*, value, Value};

struct MyObjData {
    a: i32,
}

let my_obj = Object::new("MyObj").field(Field::new(
    "a",
    TypeRef::named_nn(TypeRef::INT),
    |ctx| FieldFuture::new(async move {
        let data = ctx.parent_value.try_downcast_ref::<MyObjData>()?;
        Ok(Some(Value::from(data.a)))
    }),
));

let my_union = Union::new("MyUnion").possible_type(my_obj.type_name());

let query = Object::new("Query").field(Field::new(
    "obj",
    TypeRef::named_nn(my_union.type_name()),
    |_| FieldFuture::new(async move {
        Ok(Some(FieldValue::owned_any(MyObjData { a: 10 }).with_type("MyObj")))
    }),
));

let schema = Schema::build("Query", None, None)
    .register(my_obj)
    .register(my_union)
    .register(query)
    .finish()
    .unwrap();

assert_eq!(
   schema
       .execute("{ obj { ... on MyObj { a } } }")
       .await
       .into_result()
       .unwrap()
       .data,
   value!({ "obj": { "a": 10 } })
);

If the FieldValue is a value, returns the associated Value. Returns None otherwise.

Like as_value, but returns Result.

If the FieldValue is a list, returns the associated vector. Returns None otherwise.

Like as_list, but returns Result.

If the FieldValue is a any, returns the associated vector. Returns None otherwise.

Like downcast_ref, but returns Result.

Trait Implementations

Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

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

Returns the argument unchanged.

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

Calls U::from(self).

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

Should always be Self
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
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