diff --git a/CHANGELOG.md b/CHANGELOG.md index b9478693..83061fb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fixed integer coercion when reading variables in GraphQL API + ## [1.0.1] 2023-09-06 ### Fixed diff --git a/offchain/graphql-server/src/schema/scalar.rs b/offchain/graphql-server/src/schema/scalar.rs index 56f71237..f2d2da2d 100644 --- a/offchain/graphql-server/src/schema/scalar.rs +++ b/offchain/graphql-server/src/schema/scalar.rs @@ -121,21 +121,33 @@ impl<'de> serde::de::Visitor<'de> for RollupsGraphQLScalarValueVisitor { where E: serde::de::Error, { - Ok(RollupsGraphQLScalarValue::BigInt(value)) + if value <= i32::max_value() as i64 { + self.visit_i32(value as i32) + } else { + Ok(RollupsGraphQLScalarValue::BigInt(value)) + } } fn visit_u32(self, value: u32) -> Result where E: serde::de::Error, { - self.visit_i32(value as i32) + if value <= i32::max_value() as u32 { + self.visit_i32(value as i32) + } else { + self.visit_u64(value as u64) + } } fn visit_u64(self, value: u64) -> Result where E: serde::de::Error, { - self.visit_i64(value as i64) + if value <= i64::MAX as u64 { + self.visit_i64(value as i64) + } else { + Ok(RollupsGraphQLScalarValue::Float(value as f64)) + } } fn visit_f64(self, value: f64) -> Result {