async_graphql/types/external/
bytes.rs

1use bytes::Bytes;
2
3use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
4
5/// The `Binary` scalar type represents binary data.
6#[Scalar(internal)]
7impl ScalarType for Bytes {
8    fn parse(value: Value) -> InputValueResult<Self> {
9        match value {
10            Value::Binary(data) => Ok(data),
11            _ => Err(InputValueError::expected_type(value)),
12        }
13    }
14
15    fn is_valid(value: &Value) -> bool {
16        matches!(value, Value::Binary(_))
17    }
18
19    fn to_value(&self) -> Value {
20        Value::Binary(self.clone())
21    }
22}