Struct async_graphql::dynamic::Object
source · pub struct Object { /* private fields */ }
Available on crate feature
dynamic-schema
only.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§
source§impl Object
impl Object
sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
Set the description
sourcepub fn extends(self) -> Self
pub fn extends(self) -> Self
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
sourcepub fn inaccessible(self) -> Self
pub fn inaccessible(self) -> Self
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
sourcepub fn key(self, fields: impl Into<String>) -> Self
pub fn key(self, fields: impl Into<String>) -> Self
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");