GraphQL Client Typed Queries

Execute typed GraphQL queries with graphql-client crate in Rust for type-safe fetching.

RustData Fetching

Code

snippet
use graphql_client::GraphQLQuery;
use serde::Serialize;

#[derive(GraphQLQuery)]
#[graphql(query_path = "queries.graphql", schema_path = "schema.graphql")]
struct GetUsers;

#[derive(Serialize)]
struct Variables {
    limit: i32,
}

async fn fetch_users(endpoint: &str, vars: Variables) -> Result<GetUsers::ResponseData, Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    let res = client.post(endpoint).json(&GetUsers::build(vars)).send().await?.json().await?;
    Ok(res)
}