resolver.rs

Overview

This file implements a data loader utility for efficient batch loading of transaction records from a SQLite database. It defines the TransactionLoader struct that conforms to the async_graphql::dataloader::Loader trait, enabling asynchronous, batched queries of Transaction entities by their string IDs. This pattern is commonly used to optimize GraphQL resolver performance by minimizing redundant database queries.

The main responsibility of this file is to provide a mechanism to load multiple transactions given a set of transaction IDs (keys), returning a map of transaction IDs to their corresponding Transaction objects. It leverages the sqlx crate for asynchronous SQL query building and execution on SQLite, and the futures crate for stream processing.

Structs

TransactionLoader

pub struct TransactionLoader {
    pub pool: SqlitePool,
}

Trait Implementations

Loader for TransactionLoader

This implementation enables TransactionLoader to act as a data loader that fetches Transaction objects keyed by String IDs.

impl Loader<String> for TransactionLoader {
    type Error = Error;
    type Value = super::Transaction;

    async fn load(
        &self,
        keys: &[String],
    ) -> anyhow::Result<HashMap<String, Self::Value>, Self::Error>;
}

Implementation Details

Interactions with Other Modules

Diagram

classDiagram
class TransactionLoader {
+pool: SqlitePool
+load(keys: &[String]) Result<HashMap<String, Transaction>, Error>
}
TransactionLoader ..|> Loader
Loader <|-- TransactionLoader

References