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 Bson
Available on crate feature bson only.
impl ScalarType for Bson
bson only.Source§impl ScalarType for Tz
Available on crate feature chrono-tz only.
impl ScalarType for Tz
chrono-tz only.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 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 BigDecimal
Available on crate feature bigdecimal only.
impl ScalarType for BigDecimal
bigdecimal only.Source§impl ScalarType for DateTime
Available on crate feature bson only.
impl ScalarType for DateTime
bson only.Source§impl ScalarType for Document
Available on crate feature bson only.
impl ScalarType for Document
bson only.Source§impl ScalarType for ObjectId
Available on crate feature bson only.
impl ScalarType for ObjectId
bson only.Source§impl ScalarType for Uuid
Available on crate feature bson only.
impl ScalarType for Uuid
bson only.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 DateTime<FixedOffset>
Available on crate feature chrono only.Implement the DateTime scalar
impl ScalarType for DateTime<FixedOffset>
chrono only.Implement the DateTime
The input/output is a string in RFC3339 format.
Source§impl ScalarType for DateTime<Local>
Available on crate feature chrono only.Implement the DateTime scalar
impl ScalarType for DateTime<Local>
chrono only.Implement the DateTime
The input/output is a string in RFC3339 format.
Source§impl ScalarType for DateTime<Utc>
Available on crate feature chrono only.Implement the DateTime scalar
impl ScalarType for DateTime<Utc>
chrono only.Implement the DateTime
The input/output is a string in RFC3339 format.
Source§impl ScalarType for NaiveDate
Available on crate feature chrono only.ISO 8601 calendar date without timezone.
Format: %Y-%m-%d
impl ScalarType for NaiveDate
chrono only.ISO 8601 calendar date without timezone. Format: %Y-%m-%d
§Examples
1994-11-132000-02-24
Source§impl ScalarType for NaiveDateTime
Available on crate feature chrono only.ISO 8601 combined date and time without timezone.
impl ScalarType for NaiveDateTime
chrono only.ISO 8601 combined date and time without timezone.
§Examples
2015-07-01T08:59:60.123,
Source§impl ScalarType for NaiveTime
Available on crate feature chrono only.ISO 8601 time without timezone.
Allows for the nanosecond precision and optional leap second representation.
Format: %H:%M:%S%.f
impl ScalarType for NaiveTime
chrono only.ISO 8601 time without timezone. Allows for the nanosecond precision and optional leap second representation. Format: %H:%M:%S%.f
§Examples
08:59:60.123
Source§impl ScalarType for Decimal
Available on crate feature decimal only.
impl ScalarType for Decimal
decimal only.Source§impl ScalarType for SmolStr
Available on crate feature smol_str only.
impl ScalarType for SmolStr
smol_str only.Source§impl ScalarType for Date
Available on crate feature time only.ISO 8601 calendar date without timezone.
Format: %Y-%m-%d
impl ScalarType for Date
time only.ISO 8601 calendar date without timezone. Format: %Y-%m-%d
§Examples
1994-11-132000-02-24
Source§impl ScalarType for OffsetDateTime
Available on crate feature time only.A datetime with timezone offset.
impl ScalarType for OffsetDateTime
time only.A datetime with timezone offset.
The input is a string in RFC3339 format, e.g. “2022-01-12T04:00:19.12345Z” or “2022-01-12T04:00:19+03:00”. The output is also a string in RFC3339 format, but it is always normalized to the UTC (Z) offset, e.g. “2022-01-12T04:00:19.12345Z”.
Source§impl ScalarType for PrimitiveDateTime
Available on crate feature time only.A local datetime without timezone offset.
impl ScalarType for PrimitiveDateTime
time only.A local datetime without timezone offset.
The input/output is a string in ISO 8601 format without timezone, including subseconds. E.g. “2022-01-12T07:30:19.12345”.
Source§impl ScalarType for Url
Available on crate feature url only.URL is a String implementing the URL Standard
impl ScalarType for Url
url only.URL is a String implementing the URL Standard
Source§impl ScalarType for Uuid
Available on crate feature uuid only.A UUID is a unique 128-bit number, stored as 16 octets. UUIDs are parsed as
Strings within GraphQL. UUIDs are used to assign unique identifiers to
entities without requiring a central allocating authority.
impl ScalarType for Uuid
uuid only.A UUID is a unique 128-bit number, stored as 16 octets. UUIDs are parsed as Strings within GraphQL. UUIDs are used to assign unique identifiers to entities without requiring a central allocating authority.
§References
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 NonZeroIsize
The Int scalar type represents non-fractional whole numeric values.
impl ScalarType for NonZeroIsize
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.
Source§impl ScalarType for NonZeroUsize
The Int scalar type represents non-fractional whole numeric values.
impl ScalarType for NonZeroUsize
The Int scalar type represents non-fractional whole numeric values.
Source§impl ScalarType for Duration
Available on crate feature chrono-duration only.Implement the Duration scalar
impl ScalarType for Duration
chrono-duration only.Implement the Duration scalar
The input/output is a string in ISO8601 format.
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.
impl ScalarType for ID
impl<T: Num + Display + Send + Sync> ScalarType for StringNumber<T>
string_number only.