Struct async_graphql::dynamic::Scalar
source · pub struct Scalar { /* private fields */ }
Available on crate feature
dynamic-schema
only.Expand description
A GraphQL scalar type
Examples
use async_graphql::{dynamic::*, value, Value};
let my_scalar = Scalar::new("MyScalar");
let query = Object::new("Query").field(Field::new("value", TypeRef::named_nn(my_scalar.type_name()), |ctx| {
FieldFuture::new(async move { Ok(Some(Value::from("abc"))) })
}));
let schema = Schema::build(query.type_name(), None, None)
.register(my_scalar)
.register(query)
.finish()?;
assert_eq!(
schema
.execute("{ value }")
.await
.into_result()
.unwrap()
.data,
value!({ "value": "abc" })
);
Implementations§
source§impl Scalar
impl Scalar
sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
Set the description
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 validator(
self,
validator: impl Fn(&Value) -> bool + Send + Sync + 'static
) -> Self
pub fn validator(
self,
validator: impl Fn(&Value) -> bool + Send + Sync + 'static
) -> Self
Set the validator
sourcepub fn specified_by_url(self, specified_by_url: impl Into<String>) -> Self
pub fn specified_by_url(self, specified_by_url: impl Into<String>) -> Self
Set the specified by url