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:
parent
b673f5bd1f
commit
cecf50735b
1 changed files with 15 additions and 3 deletions
|
@ -67,14 +67,26 @@ impl<'de> de::Deserialize<'de> for InputValue {
|
||||||
Ok(InputValue::boolean(value))
|
Ok(InputValue::boolean(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_i64<E>(self, value: i64) -> Result<InputValue, E> {
|
fn visit_i64<E>(self, value: i64) -> Result<InputValue, E>
|
||||||
Ok(InputValue::int(value))
|
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>
|
fn visit_u64<E>(self, value: u64) -> Result<InputValue, E>
|
||||||
where E: de::Error,
|
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> {
|
fn visit_f64<E>(self, value: f64) -> Result<InputValue, E> {
|
||||||
|
|
Loading…
Reference in a new issue