[−][src]Trait async_graphql::ScalarType
Represents a GraphQL scalar
You can implement the trait to create a custom scalar.
Examples
use async_graphql::*; struct MyInt(i32); #[Scalar] impl ScalarType for MyInt { fn type_name() -> &'static str { "MyInt" } fn parse(value: &Value) -> Option<Self> { if let Value::Int(n) = value { Some(MyInt(*n as i32)) } else { None } } fn to_json(&self) -> Result<serde_json::Value> { Ok(self.0.into()) } }
Required methods
fn type_name() -> &'static str
The type name of a scalar.
fn parse(value: &Value) -> Option<Self>
Parse a scalar value, return Some(Self)
if successful, otherwise return None
.
fn to_json(&self) -> Result<Value>
Convert the scalar value to json value.
Provided methods
fn description() -> Option<&'static str>
The description of a scalar.
fn is_valid(value: &Value) -> bool
Checks for a valid scalar value.
The default implementation is to try to parse it, and in some cases you can implement this on your own to improve performance.
Implementations on Foreign Types
impl ScalarType for bool
[src]
fn type_name() -> &'static str
[src]
fn description() -> Option<&'static str>
[src]
fn parse(value: &Value) -> Option<Self>
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for Tz
[src]
fn type_name() -> &'static str
[src]
fn parse(value: &Value) -> Option<Self>
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for DateTime<Utc>
[src]
Implement the DateTime
The input/output is a string in RFC3339 format.