Trait async_graphql::resolver_utils::ScalarType [−][src]
pub trait ScalarType: Sized + Send {
fn parse(value: Value) -> InputValueResult<Self>;
fn to_value(&self) -> Value;
fn is_valid(_value: &Value) -> bool { ... }
}
Expand description
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::Number(n) = &value {
if let Some(n) = n.as_i64() {
return Ok(MyInt(n as i32));
}
}
Err(InputValueError::expected_type(value))
}
fn to_value(&self) -> Value {
Value::Number(self.0.into())
}
}
Required methods
fn parse(value: Value) -> InputValueResult<Self>
fn parse(value: Value) -> InputValueResult<Self>
Parse a scalar value.
Provided methods
Implementations on Foreign Types
A scalar that can represent any JSON value.
The Boolean
scalar type represents true
or false
.
The Char
scalar type represents a unicode char.
The input and output values are a string, and there can only be one unicode character in this string.
The Float
scalar type represents signed double-precision fractional values as specified by IEEE 754.
The Float
scalar type represents signed double-precision fractional values as specified by IEEE 754.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
A scalar that can represent any JSON Object value.
A scalar that can represent any JSON Object value.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
The Int
scalar type represents non-fractional whole numeric values.
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.
Implement the DateTime
The input/output is a string in RFC3339 format.
Implement the DateTime
The input/output is a string in RFC3339 format.
Implement the DateTime
The input/output is a string in RFC3339 format.
Implementors
The _Any
scalar is used to pass representations of entities from external services into the root _entities
field for execution.
impl<T: Num + Display + Send + Sync> ScalarType for StringNumber<T> where
<T as Num>::FromStrRadixErr: Display,
A scalar that can represent any JSON value.