Crate armature_graphql_client

Crate armature_graphql_client 

Source
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§

BatchRequest
A batch of GraphQL requests.
BatchResponse
A batch of GraphQL responses.
GraphQLClient
GraphQL client.
GraphQLClientConfig
GraphQL client configuration.
GraphQLClientConfigBuilder
Builder for GraphQL client configuration.
GraphQLResponse
GraphQL response from the server.
GraphQLResponseError
A GraphQL error from the server.
MutationBuilder
Mutation builder for GraphQL mutations.
QueryBuilder
Query builder for GraphQL queries.
Subscription
Subscription state for graphql-ws protocol.
SubscriptionBuilder
Subscription builder for GraphQL subscriptions.
SubscriptionStream
A GraphQL subscription stream.

Enums§

GraphQLError
GraphQL client errors.
JsonValue
Represents any valid JSON value.

Type Aliases§

Result
Result type for GraphQL client operations.