Trait async_graphql::resolver_utils::ScalarType
source · [−]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
sourcefn parse(value: Value) -> InputValueResult<Self>
fn parse(value: Value) -> InputValueResult<Self>
Parse a scalar value.
Provided Methods
Implementations on Foreign Types
sourceimpl ScalarType for bool
impl ScalarType for bool
The Boolean
scalar type represents true
or false
.
sourceimpl ScalarType for Bytes
impl ScalarType for Bytes
The Binary
scalar type represents binary data.
sourceimpl ScalarType for char
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.
sourceimpl ScalarType for f32
impl ScalarType for f32
The Float
scalar type represents signed double-precision fractional values as specified by IEEE 754.
sourceimpl ScalarType for f64
impl ScalarType for f64
The Float
scalar type represents signed double-precision fractional values as specified by IEEE 754.
sourceimpl ScalarType for i8
impl ScalarType for i8
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for i16
impl ScalarType for i16
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for i32
impl ScalarType for i32
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for i64
impl ScalarType for i64
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for u8
impl ScalarType for u8
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for u16
impl ScalarType for u16
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for u32
impl ScalarType for u32
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for u64
impl ScalarType for u64
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for usize
impl ScalarType for usize
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for isize
impl ScalarType for isize
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for NonZeroI8
impl ScalarType for NonZeroI8
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for NonZeroI16
impl ScalarType for NonZeroI16
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for NonZeroI32
impl ScalarType for NonZeroI32
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for NonZeroI64
impl ScalarType for NonZeroI64
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for NonZeroU8
impl ScalarType for NonZeroU8
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for NonZeroU16
impl ScalarType for NonZeroU16
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for NonZeroU32
impl ScalarType for NonZeroU32
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for NonZeroU64
impl ScalarType for NonZeroU64
The Int
scalar type represents non-fractional whole numeric values.
sourceimpl ScalarType for String
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.
sourceimpl ScalarType for BigDecimal
impl ScalarType for BigDecimal
sourceimpl ScalarType for ObjectId
impl ScalarType for ObjectId
sourceimpl ScalarType for Uuid
impl ScalarType for Uuid
sourceimpl ScalarType for UtcDateTime
impl ScalarType for UtcDateTime
sourceimpl ScalarType for Bson
impl ScalarType for Bson
sourceimpl ScalarType for Document
impl ScalarType for Document
sourceimpl ScalarType for Tz
impl ScalarType for Tz
sourceimpl ScalarType for DateTime<FixedOffset>
impl ScalarType for DateTime<FixedOffset>
Implement the DateTime
The input/output is a string in RFC3339 format.
sourceimpl ScalarType for DateTime<Local>
impl ScalarType for DateTime<Local>
Implement the DateTime
The input/output is a string in RFC3339 format.
sourceimpl ScalarType for DateTime<Utc>
impl ScalarType for DateTime<Utc>
Implement the DateTime
The input/output is a string in RFC3339 format.
sourceimpl ScalarType for Decimal
impl ScalarType for Decimal
sourceimpl ScalarType for Duration
impl ScalarType for Duration
Implement the Duration scalar
The input/output is a string in ISO8601 format.
sourceimpl ScalarType for NaiveDate
impl ScalarType for NaiveDate
sourceimpl ScalarType for NaiveTime
impl ScalarType for NaiveTime
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
sourceimpl ScalarType for NaiveDateTime
impl ScalarType for NaiveDateTime
sourceimpl ScalarType for SmolStr
impl ScalarType for SmolStr
sourceimpl ScalarType for Date
impl ScalarType for Date
sourceimpl ScalarType for OffsetDateTime
impl ScalarType for OffsetDateTime
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”.
sourceimpl ScalarType for PrimitiveDateTime
impl ScalarType for PrimitiveDateTime
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”.
sourceimpl ScalarType for Url
impl ScalarType for Url
URL is a String implementing the URL Standard
sourceimpl ScalarType for Uuid
impl ScalarType for Uuid
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
sourceimpl ScalarType for Uuid
impl ScalarType for Uuid
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
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.