Merge branches 'master' and 'master' of github.com:async-graphql/async-graphql

This commit is contained in:
Sunli 2022-05-27 15:23:53 +08:00
commit fb6a8b29e6
7 changed files with 49 additions and 3 deletions

View File

@ -68,6 +68,7 @@ opentelemetry = { version = "0.17.0", optional = true, default-features = false,
"trace",
] }
rust_decimal = { version = "1.14.3", optional = true }
bigdecimal = { version = "0.3.0", optional = true }
secrecy = { version = "0.8.0", optional = true }
smol_str = { version = "0.1.21", optional = true }
time = { version = "0.3.5", optional = true, features = [

View File

@ -32,7 +32,7 @@ impl Query {
};
}
let mut connection = Connection::new(start > 0, end < 10000);
connection.append(
connection.edges.extend(
(start..end).into_iter().map(|n|
Ok(Edge::with_additional_fields(n, n as i32, EmptyFields)),
))?;

View File

@ -34,7 +34,7 @@ impl Query {
};
}
let mut connection = Connection::new(start > 0, end < 10000);
connection.append(
connection.edges.extend(
(start..end).into_iter().map(|n|
Ok(Edge::new_with_additional_fields(n, n as i32, EmptyFields)),
))?;

View File

@ -44,7 +44,7 @@ where
/// A cursor for use in pagination
pub(crate) cursor: CursorScalar<Cursor>,
/// "The item at the end of the edge
pub(crate) node: Node,
pub node: Node,
#[graphql(flatten)]
pub(crate) additional_fields: EdgeFields,
}

31
src/types/external/big_decimal.rs vendored Normal file
View File

@ -0,0 +1,31 @@
use std::str::FromStr;
use bigdecimal::BigDecimal;
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
#[Scalar(internal, name = "BigDecimal")]
impl ScalarType for BigDecimal {
fn parse(value: Value) -> InputValueResult<Self> {
match &value {
Value::Number(n) => {
if let Some(f) = n.as_f64() {
return BigDecimal::try_from(f).map_err(InputValueError::custom);
}
if let Some(f) = n.as_i64() {
return Ok(BigDecimal::from(f));
}
// unwrap safe here, because we have check the other possibility
Ok(BigDecimal::from(n.as_u64().unwrap()))
}
Value::String(s) => Ok(BigDecimal::from_str(s)?),
_ => Err(InputValueError::expected_type(value)),
}
}
fn to_value(&self) -> Value {
Value::String(self.to_string())
}
}

View File

@ -9,6 +9,18 @@ impl ScalarType for Decimal {
fn parse(value: Value) -> InputValueResult<Self> {
match &value {
Value::String(s) => Ok(Decimal::from_str(s)?),
Value::Number(n) => {
if let Some(f) = n.as_f64() {
return Decimal::try_from(f).map_err(InputValueError::custom);
}
if let Some(f) = n.as_i64() {
return Ok(Decimal::from(f));
}
// unwrap safe here, because we have check the other possibility
Ok(Decimal::from(n.as_u64().unwrap()))
}
_ => Err(InputValueError::expected_type(value)),
}
}

View File

@ -15,6 +15,8 @@ mod string;
#[cfg(feature = "tokio-sync")]
mod tokio;
#[cfg(feature = "bigdecimal")]
mod big_decimal;
#[cfg(feature = "bson")]
mod bson;
#[cfg(feature = "chrono-tz")]