Limit incoming integers to the 32 bit signed range

Also related to #49 - unsigned integers will no longer be represented
as floats.

While this spec might break clients, it makes Juniper follow the GraphQL
specification more closely
This commit is contained in:
Magnus Hallin 2017-06-15 10:37:30 +02:00
parent b673f5bd1f
commit cecf50735b

View file

@ -67,14 +67,26 @@ impl<'de> de::Deserialize<'de> for InputValue {
Ok(InputValue::boolean(value))
}
fn visit_i64<E>(self, value: i64) -> Result<InputValue, E> {
fn visit_i64<E>(self, value: i64) -> Result<InputValue, E>
where E: de::Error,
{
if value >= i32::min_value() as i64 && value <= i32::max_value() as i64 {
Ok(InputValue::int(value))
}
else {
Err(E::custom(format!("integer out of range")))
}
}
fn visit_u64<E>(self, value: u64) -> Result<InputValue, E>
where E: de::Error,
{
self.visit_f64(value as f64)
if value <= i32::max_value() as u64 {
self.visit_i64(value as i64)
}
else {
Err(E::custom(format!("integer out of range")))
}
}
fn visit_f64<E>(self, value: f64) -> Result<InputValue, E> {