Graphql_client reqwest integration/support does not work
⚓ Rust 📅 2025-09-26 👤 surdeus 👁️ 9Was trying to use graphql_client (GitHub - graphql-rust/graphql-client: Typed, correct GraphQL requests and responses in Rust) to work with github API, however I was unable to get either of the documented methods of use to work.
One method is to use the provided post_graphql function:
    use graphql_client::{reqwest::post_graphql_blocking as post_graphql, GraphQLQuery};
    use reqwest::blocking::Client;
    let client = Client::builder()
        .user_agent("graphql-rust/0.10.0")
        .default_headers(
            std::iter::once((
                reqwest::header::AUTHORIZATION,
                reqwest::header::HeaderValue::from_str(&format!("Bearer {}", PERSONAL_ACCESS_TOKEN))
                    .unwrap(),
            ))
                .collect(),
        )
        .build()?;
    let variables = github::project_id::Variables {
        number: 1,
        organization: organization.into()
    };
    let response_body =
        post_graphql::<github::ProjectId, _>(&client, github_api, variables)?;
This does not work because the graphql_client provides it's own version of reqwest somehow which conflicts with the one I have in my project. I could not find a way to use the version used by graphql_client. They also do not appear to be conflicting versions, ">=0.11, <=0.12" and 0.12.23, so I don't even know what caused this issue.
error[E0308]: mismatched types
   --> src/main.rs:148:46
    |
148 |         post_graphql::<github::ProjectId, _>(&client, "https://api.github.com/graphql", variables).unwrap();
    |         ------------------------------------ ^^^^^^^ expected `reqwest::blocking::client::Client`, found `reqwest::blocking::Client`
    |         |
    |         arguments to this function are incorrect
    |
note: two different versions of crate `reqwest` are being used; two types coming from two different versions of the same crate are different types even if they look the same
The other method
    let query = github::ProjectId::build_query(variables);
    let response = client.post(github_api).body(&query).send()?;
also does not work because graphql_client does not implement the required trait for reqwest.
error[E0277]: the trait bound `reqwest::blocking::Body: From<&QueryBody<Variables>>` is not satisfied
   --> src/main.rs:149:49
    |
149 |     let response = client.post(github_api).body(&query).send()?;
    |                                            ---- ^^^^^^ the trait `From<&QueryBody<Variables>>` is not implemented for `reqwest::blocking::Body`
    |                                            |
    |                                            required by a bound introduced by this call
    |
    = help: the following other types implement trait `From<T>`:
              `reqwest::blocking::Body` implements `From<&[u8]>`
              `reqwest::blocking::Body` implements `From<&str>`
              `reqwest::blocking::Body` implements `From<File>`
              `reqwest::blocking::Body` implements `From<Vec<u8>>`
              `reqwest::blocking::Body` implements `From<bytes::bytes::Bytes>`
              `reqwest::blocking::Body` implements `From<std::string::String>`
    = note: required for `&QueryBody<Variables>` to implement `Into<reqwest::blocking::Body>`
I eventually got it to work by manually serializing the query, but it feels like both of the other two approaches should have worked. Did I miss something obvious or is this crate kind of broken?
    let b = serde_json::to_value(
        &query
    )?.to_string();
    let response = client.post(github_api).body(b).send()?;
    let response_body: Response<github::project_id::ResponseData> = response.json()?;
1 post - 1 participant
🏷️ Rust_feed