mod.rs

Overview

This file defines the root GraphQL query object for a blockchain-related system, facilitating the retrieval of core data entities such as blockchain blocks, account information, and general system info. It leverages asynchronous GraphQL resolvers combined with a SQLite database connection pool to execute queries efficiently. The file organizes query handling logic for the GraphQL API, interfacing with database models and other GraphQL submodules.

Components

QueryRoot Struct

QueryRoot is the main struct representing the root GraphQL query entry point. It exposes multiple asynchronous query methods decorated with the #[Object] procedural macro from async_graphql to define GraphQL object fields.


Methods on QueryRoot

1. info

async fn info(&self, ctx: &Context<'_>) -> FieldResult<Option<Info>>

2. account

async fn account(&self, address: String) -> Option<AccountQuery>

3. blocks

async fn blocks(
    &self,
    ctx: &Context<'_>,
    filter: Option<BlockFilter>,
    order_by: Option<Vec<Option<QueryOrderBy>>>,
    limit: Option<i32>,
) -> FieldResult<Option<Vec<Option<Block>>>>

Implementation Details and Algorithms


Interactions with Other System Components


Diagram: QueryRoot Structure and Method Interactions

classDiagram
class QueryRoot {
+info(ctx)
+account(address)
+blocks(ctx, filter, order_by, limit)
}
class SqlitePool
class Context {
+data<T>()
+look_ahead()
+data_unchecked<T>()
}
class Block
class BlockFilter
class QueryOrderBy
class AccountQuery
class Info
class MessageLoader
QueryRoot --> Context
QueryRoot --> SqlitePool
QueryRoot --> Block
QueryRoot --> BlockFilter
QueryRoot --> QueryOrderBy
QueryRoot --> AccountQuery
QueryRoot --> Info
QueryRoot --> MessageLoader
Context --> SqlitePool
Context --> MessageLoader

This file primarily focuses on the GraphQL query API layer responsible for retrieving blockchain data and related entities, orchestrating database access and data transformation to match GraphQL schema expectations. It is a critical integration point between the database schema and the GraphQL schema, enabling flexible queries based on client requirements.