[−][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) -> InputValueResult<Self> { if let Value::Int(n) = value { Ok(MyInt(n as i32)) } else { Err(InputValueError::ExpectedType(value)) } } 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) -> InputValueResult<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.
Implementing this function can find incorrect input values during the verification phase, which can 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) -> InputValueResult<Self>
[src]
fn is_valid(value: &Value) -> bool
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for Tz
[src]
fn type_name() -> &'static str
[src]
fn parse(value: Value) -> InputValueResult<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.
fn type_name() -> &'static str
[src]
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for f32
[src]
fn type_name() -> &'static str
[src]
fn description() -> Option<&'static str>
[src]
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn is_valid(value: &Value) -> bool
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for f64
[src]
fn type_name() -> &'static str
[src]
fn description() -> Option<&'static str>
[src]
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn is_valid(value: &Value) -> bool
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for i8
[src]
fn type_name() -> &'static str
[src]
fn description() -> Option<&'static str>
[src]
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn is_valid(value: &Value) -> bool
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for i16
[src]
fn type_name() -> &'static str
[src]
fn description() -> Option<&'static str>
[src]
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn is_valid(value: &Value) -> bool
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for i32
[src]
fn type_name() -> &'static str
[src]
fn description() -> Option<&'static str>
[src]
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn is_valid(value: &Value) -> bool
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for u8
[src]
fn type_name() -> &'static str
[src]
fn description() -> Option<&'static str>
[src]
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn is_valid(value: &Value) -> bool
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for u16
[src]
fn type_name() -> &'static str
[src]
fn description() -> Option<&'static str>
[src]
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn is_valid(value: &Value) -> bool
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for u32
[src]
fn type_name() -> &'static str
[src]
fn description() -> Option<&'static str>
[src]
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn is_valid(value: &Value) -> bool
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for i64
[src]
fn type_name() -> &'static str
[src]
fn description() -> Option<&'static str>
[src]
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn is_valid(value: &Value) -> bool
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for u64
[src]
fn type_name() -> &'static str
[src]
fn description() -> Option<&'static str>
[src]
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn is_valid(value: &Value) -> bool
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for NaiveDate
[src]
Implement the NaiveDate scalar
fn type_name() -> &'static str
[src]
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for NaiveTime
[src]
Implement the NaiveTime scalar