Announcing async-graphql-dataloader: A high-performance DataLoader implementation for async-graphql
⚓ Rust 📅 2025-12-21 👤 surdeus 👁️ 2Hello Rust community,
I'm pleased to announce the first public release of async-graphql-dataloader , a DataLoader pattern implementation designed for native integration with the async-graphql ecosystem.
Goal: Efficiently solve the N+1 problem in Rust GraphQL servers by providing automatic request batching and request-scoped caching.
Key Features:
- Automatic Batching: Multiple
.load()calls are automatically coalesced into a single batch. - Intelligent Caching: Request-scoped caching using
DashMap, preventing duplicate loads. - Seamless Integration: Works out-of-the-box with
async-graphqlvia context injection. - Flexible: The
Loadertrait can be implemented for any data source (SQL DBs, HTTP APIs, etc.). - Async Native: Built on
tokioandasync/await. - Example usage in a resolver:
use async_graphql_dataloader::{DataLoader, Loader};
use std::collections::HashMap;
struct UserLoader;
#[async_trait::async_trait]
impl Loader for UserLoader {
type Value = String;
type Error = std::convert::Infallible;
async fn load(&self, keys: &[i32]) -> Result<HashMap<i32, Self::Value>, Self::Error> {
Ok(keys.iter().map(|&k| (k, format!("User {}", k))).collect())
}
}
// In your GraphQL resolver
async fn get_users(ctx: &async_graphql::Context<'_>, ids: Vec) -> async_graphql::Result<Vec> {
let loader = ctx.data_unchecked::<DataLoader>();
let futures = ids.into_iter().map(|id| loader.load_one(id));
let users = futures::future::join_all(futures).await;
users.into_iter().collect()
}
The crate is stable for use, and community feedback is highly welcomed, especially on:
- The API and
Loadertrait design. - Advanced use cases or edge conditions.
- Ideas for future features.
Links:
- Crates.io:
async-graphql-dataloader - Documentation: docs.rs/async-graphql-dataloader
- Source Code & Issues: GitHub Repository
Thank you for your interest. I look forward to constructive discussions and contributions.
Cleiton Augusto Correa Bezerra
1 post - 1 participant
🏷️ Rust_feed