2020-05-26 10:34:43 +00:00
|
|
|
use crate::{InputValueError, InputValueResult, ScalarType, Value};
|
2020-04-27 09:58:10 +00:00
|
|
|
use async_graphql_derive::Scalar;
|
2020-03-20 03:56:08 +00:00
|
|
|
use url::Url;
|
|
|
|
|
2020-04-27 09:58:10 +00:00
|
|
|
#[Scalar(internal)]
|
|
|
|
impl ScalarType for Url {
|
2020-05-11 13:47:24 +00:00
|
|
|
fn parse(value: Value) -> InputValueResult<Self> {
|
2020-03-20 03:56:08 +00:00
|
|
|
match value {
|
2020-05-11 13:47:24 +00:00
|
|
|
Value::String(s) => Ok(Url::parse(&s)?),
|
|
|
|
_ => Err(InputValueError::ExpectedType(value)),
|
2020-03-20 03:56:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-26 10:34:43 +00:00
|
|
|
fn to_value(&self) -> Value {
|
|
|
|
Value::String(self.to_string())
|
2020-03-20 03:56:08 +00:00
|
|
|
}
|
|
|
|
}
|