1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
pub mod account;
pub mod account_set;
pub mod balance;
mod convert;
mod job;
pub mod journal;
pub mod loader;
pub mod primitives;
mod schema;
mod timestamp;
pub mod transaction;
pub mod tx_template;

use async_graphql::{dataloader::*, *};

pub use job::Job;
pub use schema::*;

use crate::{app::CalaApp, extension::*};
use loader::LedgerDataLoader;

pub fn schema<Q: QueryExtensionMarker, M: MutationExtensionMarker>(
    app: Option<CalaApp>,
) -> Schema<CoreQuery<Q>, CoreMutation<M>, EmptySubscription> {
    let schema = Schema::build(
        CoreQuery::<Q>::default(),
        CoreMutation::<M>::default(),
        EmptySubscription,
    );
    if let Some(app) = app {
        schema
            .data(
                DataLoader::new(
                    LedgerDataLoader {
                        ledger: app.ledger().clone(),
                    },
                    tokio::task::spawn,
                )
                // Set delay to 0 as per https://github.com/async-graphql/async-graphql/issues/1306
                .delay(std::time::Duration::from_secs(0)),
            )
            .data(app)
            .finish()
    } else {
        schema.finish()
    }
}