pub trait ScalarType: Sized + Send {
// Required methods
fn parse(value: Value) -> InputValueResult<Self>;
fn to_value(&self) -> Value;
// Provided method
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§
Sourcefn parse(value: Value) -> InputValueResult<Self>
fn parse(value: Value) -> InputValueResult<Self>
Parse a scalar value.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl ScalarType for bool
The Boolean
scalar type represents true
or false
.
impl ScalarType for bool
The Boolean
scalar type represents true
or false
.
Source§impl ScalarType for char
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.
impl ScalarType for char
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.
Source§impl ScalarType for f32
The Float
scalar type represents signed double-precision fractional values as specified by IEEE 754.
impl ScalarType for f32
The Float
scalar type represents signed double-precision fractional values as specified by IEEE 754.
Source§impl ScalarType for f64
The Float
scalar type represents signed double-precision fractional values as specified by IEEE 754.
impl ScalarType for f64
The Float
scalar type represents signed double-precision fractional values as specified by IEEE 754.
Source§impl ScalarType for i8
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for i8
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for i16
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for i16
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for i32
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for i32
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for i64
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for i64
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for isize
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for isize
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for u8
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for u8
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for u16
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for u16
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for u32
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for u32
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for u64
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for u64
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for usize
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for usize
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for Bytes
The Binary
scalar type represents binary data.
impl ScalarType for Bytes
The Binary
scalar type represents binary data.
Source§impl ScalarType for String
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.
impl ScalarType for String
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.
Source§impl ScalarType for NonZeroI8
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for NonZeroI8
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for NonZeroI16
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for NonZeroI16
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for NonZeroI32
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for NonZeroI32
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for NonZeroI64
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for NonZeroI64
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for NonZeroU8
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for NonZeroU8
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for NonZeroU16
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for NonZeroU16
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for NonZeroU32
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for NonZeroU32
The Int
scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for NonZeroU64
The Int
scalar type represents non-fractional whole numeric values.
impl ScalarType for NonZeroU64
The Int
scalar type represents non-fractional whole numeric values.
Implementors§
impl ScalarType for Any
The _Any
scalar is used to pass representations of entities from external
services into the root _entities
field for execution.