Add Any::parse_value method.
use crate::{Result, ScalarType, Value};
use async_graphql_derive::Scalar;
use itertools::Itertools;
+use serde::de::DeserializeOwned;
/// Any scalar
///
@@ -31,6 +32,13 @@ impl ScalarType for Any {
}
}
+impl Any {
+ /// Parse this `Any` value to T by `serde_json`.
+ fn parse_value<T: DeserializeOwned>(&self) -> std::result::Result<T, serde_json::Error> {
+ serde_json::from_value(self.to_json().unwrap())
+ }
+}
+
fn gql_value_to_json_value(value: &Value) -> serde_json::Value {
match value {
Value::Null => serde_json::Value::Null,
