graphql-rust / graphql-client

Typed, correct GraphQL requests and responses in Rust
Apache License 2.0
1.12k stars 152 forks source link

Use String deserialization for bigInt #464

Open Doozers opened 7 months ago

Doozers commented 7 months ago

Hi,

graphql use string type to represent big integers but the rusts bigint's types deserialise expecting a tuple (sign, value) so I'm having issues to deal with big integers.

use num_bigint::BigInt;
use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct Data {
    num: BigInt,
}

fn main() {
    let data = r#"
        {
            "num": "111111111111111111111111111111111111",
        }
    "#;

    let d: Data = serde_json::from_str(data).unwrap();
    println!("{}", d.num);
}
thread 'main' panicked at src/main.rs:16:46:
called `Result::unwrap()` on an `Err` value: Error("invalid type: string \"111111111111111111111111111111111111\", expected a tuple of size 2", line: 3, column: 57)

code example to explain the problem, but the real-case error message is:

Error: reqwest::Error { kind: Decode, source: Error("invalid type: string \"29686942926033387970\", expected a tuple of size 2", line: 1, column: 177) }

what is the best way to bypass these issues ?