MCPcopy Index your code
hub / github.com/arthurkhlghatyan/gql-client-rs

github.com/arthurkhlghatyan/gql-client-rs @v1.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.0 ↗ · + Follow
38 symbols 44 edges 8 files 0 documented · 0% updated 2mo agov1.1.0 · 2026-01-29★ 52

Browse by type

Functions 22 Types & classes 16
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

gql_client

Minimal GraphQL client for Rust

Build Status crates.io docs

  • Simple API, supports queries and mutations
  • Does not require schema file for introspection
  • Supports WebAssembly

Basic Usage

  • Use client.query_with_vars for queries with variables
  • There's also a wrapper client.query if there is no need to pass variables

```rust use gql_client::Client; use serde::{Deserialize, Serialize};

[derive(Deserialize)]

pub struct Data { user: User }

[derive(Deserialize)]

pub struct User { id: String, name: String }

[derive(Serialize)]

pub struct Vars { id: u32 }

[tokio::main]

async fn main() -> Result<(), Box> { let endpoint = "https://graphqlzero.almansi.me/api"; let query = r#" query UserByIdQuery($id: ID!) { user(id: $id) { id name } } "#;

let client = Client::new(endpoint);
let vars = Vars { id: 1 };
let data = client.query_with_vars::<Data, Vars>(query, vars).await.unwrap().unwrap();

println!("Id: {}, Name: {}", data.user.id, data.user.name);

Ok(())

} ```

Passing HTTP headers

Client exposes new_with_headers function to pass headers using simple HashMap<&str, &str>

```rust use gql_client::Client; use std::collections::HashMap;

[tokio::main]

async fn main() -> Result<(), Box> { let endpoint = "https://graphqlzero.almansi.me/api"; let mut headers = HashMap::new(); headers.insert("authorization", "Bearer ");

let client = Client::new_with_headers(endpoint, headers);

Ok(())

} ```

Error handling

There are two types of errors that can possibly occur. HTTP related errors (for example, authentication problem) or GraphQL query errors in JSON response. Debug, Display implementation of GraphQLError struct properly displays those error messages. Additionally, you can also look at JSON content for more detailed output by calling err.json()

```rust use gql_client::Client; use serde::{Deserialize, Serialize};

[derive(Deserialize)]

pub struct Data { user: User }

[derive(Deserialize)]

pub struct User { id: String, name: String }

[derive(Serialize)]

pub struct Vars { id: u32 }

[tokio::main]

async fn main() -> Result<(), Box> { let endpoint = "https://graphqlzero.almansi.me/api";

// Send incorrect request
let query = r#"
    query UserByIdQuery($id: ID!) {
        user(id: $id) {
            id1
            name
        }
    }
"#;

let client = Client::new(endpoint);
let vars = Vars { id: 1 };
let error = client.query_with_vars::<Data, Vars>(query, vars).await.err();

println!("{:?}", error);

Ok(())

} ```

Core symbols most depended-on inside this repo

Shape

Method 17
Class 14
Function 5
Enum 2

Languages

Rust100%

Modules by API surface

src/error.rs12 symbols
src/client.rs12 symbols
tests/structs.rs5 symbols
src/types.rs5 symbols
tests/queries.rs2 symbols
tests/reqwest.rs1 symbols
tests/errors.rs1 symbols

For agents

$ claude mcp add gql-client-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page