Skip to content

Commit f1ecde2

Browse files
committed
Improve BigDecimal parsing from Float with ryu crate (#1176)
1 parent d9dfae6 commit f1ecde2

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

juniper/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ default = [
3131
"url",
3232
"uuid",
3333
]
34-
bigdecimal = ["dep:bigdecimal"]
34+
bigdecimal = ["dep:bigdecimal", "dep:ryu"]
3535
bson = ["dep:bson"]
3636
chrono = ["dep:chrono"]
3737
chrono-clock = ["chrono", "chrono/clock"]
@@ -59,6 +59,7 @@ graphql-parser = { version = "0.4", optional = true }
5959
indexmap = { version = "2.0", features = ["serde"] }
6060
juniper_codegen = { version = "0.16.0-dev", path = "../juniper_codegen" }
6161
rust_decimal = { version = "1.20", default-features = false, optional = true }
62+
ryu = { version = "1.0", optional = true }
6263
serde = { version = "1.0.122", features = ["derive"] }
6364
serde_json = { version = "1.0.18", default-features = false, optional = true }
6465
smartstring = "1.0"

juniper/src/integrations/bigdecimal.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ mod bigdecimal_scalar {
4444
} else if let Some(f) = v.as_float_value() {
4545
// See akubera/bigdecimal-rs#103 for details:
4646
// https://github.com/akubera/bigdecimal-rs/issues/103
47-
BigDecimal::from_str(&f.to_string())
47+
let mut buf = ryu::Buffer::new();
48+
BigDecimal::from_str(buf.format(f))
4849
.map_err(|e| format!("Failed to parse `BigDecimal` from `Float`: {e}"))
4950
} else {
5051
v.as_string_value()

0 commit comments

Comments
 (0)