pub struct Object { /* private fields */ }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
Sourcepub fn interface_object(self) -> Self
pub fn interface_object(self) -> Self
During composition, the fields of every @interfaceObject are added
both to their corresponding interface definition and to all
entity types that implement that interface.
Reference: https://www.apollographql.com/docs/federation/federated-types/federated-directives/#interfaceobject
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::{Value, dynamic::*};
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");Sourcepub fn unresolvable(self, fields: impl Into<String>) -> Self
pub fn unresolvable(self, fields: impl Into<String>) -> Self
Make the entity unresolvable by the current subgraph
Most commonly used to reference an entity without contributing fields.
§Examples
use async_graphql::{Value, dynamic::*};
let obj = Object::new("MyObj")
.field(Field::new("a", TypeRef::named(TypeRef::INT), |_| {
FieldFuture::new(async move { Ok(Some(Value::from(10))) })
}))
.unresolvable("a");This references the MyObj entity with the key a that cannot be
resolved by the current subgraph.