Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
fix(graphql-server): integer coercion in variables
Browse files Browse the repository at this point in the history
Without this patch, the integer variables are always interpreted as
BigInts.
  • Loading branch information
gligneul committed Sep 10, 2023
1 parent 1a0fa93 commit ae646c0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions offchain/graphql-server/src/schema/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E>(self, value: u32) -> Result<RollupsGraphQLScalarValue, E>
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<E>(self, value: u64) -> Result<RollupsGraphQLScalarValue, E>
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<E>(self, value: f64) -> Result<RollupsGraphQLScalarValue, E> {
Expand Down

0 comments on commit ae646c0

Please sign in to comment.