pub struct Object { /* private fields */ }
Expand description

A GraphQL object type

Examples

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

let query = Object::new("Query").field(Field::new("value", TypeRef::named_nn(TypeRef::STRING), |ctx| {
    FieldFuture::new(async move { Ok(Some(Value::from("abc"))) })
}));


let schema = Schema::build(query.type_name(), None, None)
    .register(query)
    .finish()?;

assert_eq!(
   schema
       .execute("{ value }")
       .await
       .into_result()
       .unwrap()
       .data,
   value!({ "value": "abc" })
);

Implementations§

Create a GraphQL object type

Set the description

Indicates that an object or interface definition is an extension of another definition of that same type.

Indicate that an object type’s field is allowed to be resolved by multiple subgraphs

Indicate that an enum is not accessible from a supergraph when using Apollo Federation

Reference: https://www.apollographql.com/docs/federation/federated-types/federated-directives/#inaccessible

Arbitrary string metadata that will be propagated to the supergraph when using Apollo Federation. This attribute is repeatable

Reference: https://www.apollographql.com/docs/federation/federated-types/federated-directives/#applying-metadata

Add an field to the object

Add an implement to the object

Add an entity key

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

let obj = Object::new("MyObj")
    .field(Field::new("a", TypeRef::named(TypeRef::INT), |_| {
        FieldFuture::new(async move { Ok(Some(Value::from(10))) })
    }))
    .field(Field::new("b", TypeRef::named(TypeRef::INT), |_| {
        FieldFuture::new(async move { Ok(Some(Value::from(20))) })
    }))
    .field(Field::new("c", TypeRef::named(TypeRef::INT), |_| {
        FieldFuture::new(async move { Ok(Some(Value::from(30))) })
    }))
    .key("a b")
    .key("c");

Returns the type name

Trait Implementations§

Formats the value using the given formatter. Read more
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.

Calls U::from(self).

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

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.