Expand description
§Armature GraphQL Client
A type-safe GraphQL client with support for queries, mutations, and subscriptions.
§Features
- Type-safe queries: Generate Rust types from GraphQL schema
- Subscriptions: WebSocket-based GraphQL subscriptions
- Batching: Batch multiple queries into a single request
- Caching: Optional response caching
- Federation: Support for Apollo Federation
§Quick Start
ⓘ
use armature_graphql_client::{GraphQLClient, GraphQLClientConfig};
use serde::{Deserialize, Serialize};
#[derive(Serialize)]
struct GetUserVars {
id: String,
}
#[derive(Deserialize)]
struct User {
id: String,
name: String,
}
#[derive(Deserialize)]
struct GetUserResponse {
user: User,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = GraphQLClient::new("https://api.example.com/graphql");
let response: GetUserResponse = client
.query("query GetUser($id: ID!) { user(id: $id) { id name } }")
.variables(GetUserVars { id: "123".into() })
.send()
.await?;
println!("User: {}", response.user.name);
Ok(())
}§Subscriptions
ⓘ
use armature_graphql_client::GraphQLClient;
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = GraphQLClient::new("wss://api.example.com/graphql");
let mut subscription = client
.subscribe("subscription { messageAdded { id content } }")
.send()
.await?;
while let Some(result) = subscription.next().await {
match result {
Ok(data) => println!("Received: {:?}", data),
Err(e) => eprintln!("Error: {}", e),
}
}
Ok(())
}Structs§
- Batch
Request - A batch of GraphQL requests.
- Batch
Response - A batch of GraphQL responses.
- GraphQL
Client - GraphQL client.
- GraphQL
Client Config - GraphQL client configuration.
- GraphQL
Client Config Builder - Builder for GraphQL client configuration.
- GraphQL
Response - GraphQL response from the server.
- GraphQL
Response Error - A GraphQL error from the server.
- Mutation
Builder - Mutation builder for GraphQL mutations.
- Query
Builder - Query builder for GraphQL queries.
- Subscription
- Subscription state for graphql-ws protocol.
- Subscription
Builder - Subscription builder for GraphQL subscriptions.
- Subscription
Stream - A GraphQL subscription stream.
Enums§
- GraphQL
Error - GraphQL client errors.
- Json
Value - Represents any valid JSON value.
Type Aliases§
- Result
- Result type for GraphQL client operations.