[−][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 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 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 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]
The Boolean
scalar type represents true
or false
.
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn is_valid(value: &Value) -> bool
[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.
impl ScalarType for f32
The Float
scalar type represents signed double-precision fractional values as specified by IEEE 754.
fn parse(value: Value) -> InputValueResult<Self>
fn is_valid(value: &Value) -> bool
fn to_json(&self) -> Result<Value>
impl ScalarType for f64
The Float
scalar type represents signed double-precision fractional values as specified by IEEE 754.
fn parse(value: Value) -> InputValueResult<Self>
fn is_valid(value: &Value) -> bool
fn to_json(&self) -> Result<Value>
impl ScalarType for i8
The Int
scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
fn parse(value: Value) -> InputValueResult<Self>
fn is_valid(value: &Value) -> bool
fn to_json(&self) -> Result<Value>
impl ScalarType for i16
The Int
scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
fn parse(value: Value) -> InputValueResult<Self>
fn is_valid(value: &Value) -> bool
fn to_json(&self) -> Result<Value>
impl ScalarType for i32
The Int
scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
fn parse(value: Value) -> InputValueResult<Self>
fn is_valid(value: &Value) -> bool
fn to_json(&self) -> Result<Value>
impl ScalarType for u8
The Int
scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
fn parse(value: Value) -> InputValueResult<Self>
fn is_valid(value: &Value) -> bool
fn to_json(&self) -> Result<Value>
impl ScalarType for u16
The Int
scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
fn parse(value: Value) -> InputValueResult<Self>
fn is_valid(value: &Value) -> bool
fn to_json(&self) -> Result<Value>
impl ScalarType for u32
The Int
scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
fn parse(value: Value) -> InputValueResult<Self>
fn is_valid(value: &Value) -> bool
fn to_json(&self) -> Result<Value>
impl ScalarType for i64
The Int64
scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^64) and 2^64 - 1.
fn parse(value: Value) -> InputValueResult<Self>
fn is_valid(value: &Value) -> bool
fn to_json(&self) -> Result<Value>
impl ScalarType for u64
The Int64
scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^64) and 2^64 - 1.
fn parse(value: Value) -> InputValueResult<Self>
fn is_valid(value: &Value) -> bool
fn to_json(&self) -> Result<Value>
impl ScalarType for NaiveDate
[src]
impl ScalarType for NaiveTime
[src]
impl ScalarType for String
[src]
The String
scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn is_valid(value: &Value) -> bool
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for ObjectId
[src]
impl ScalarType for UtcDateTime
[src]
impl ScalarType for Url
[src]
impl ScalarType for Uuid
[src]
Loading content...
Implementors
impl ScalarType for Any
[src]
The _Any
scalar is used to pass representations of entities from external services into the root _entities
field for execution.
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn is_valid(_value: &Value) -> bool
[src]
fn to_json(&self) -> Result<Value>
[src]
impl ScalarType for Cursor
[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 ID
[src]
fn parse(value: Value) -> InputValueResult<Self>
[src]
fn is_valid(value: &Value) -> bool
[src]
fn to_json(&self) -> Result<Value>
[src]
impl<T: DeserializeOwned + Serialize + Send + Sync> ScalarType for Json<T>
[src]
A scalar that can represent any JSON value.