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

Parse a scalar value.

Convert the scalar to Value.

Provided methods

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

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 scalar

The input/output is a string in RFC3339 format.

Implement the DateTime scalar

The input/output is a string in RFC3339 format.

Implement the DateTime scalar

The input/output is a string in RFC3339 format.

Implementors