cala_server/graphql/
mod.rs

1pub mod account;
2pub mod account_set;
3pub mod balance;
4mod convert;
5mod job;
6pub mod journal;
7pub mod loader;
8pub mod primitives;
9mod schema;
10mod timestamp;
11pub mod transaction;
12pub mod tx_template;
13pub mod velocity;
14
15use async_graphql::{dataloader::*, *};
16
17pub use job::Job;
18pub use schema::*;
19
20use crate::{app::CalaApp, extension::*};
21use loader::LedgerDataLoader;
22
23pub fn schema<Q: QueryExtensionMarker, M: MutationExtensionMarker>(
24    app: Option<CalaApp>,
25) -> Schema<CoreQuery<Q>, CoreMutation<M>, EmptySubscription> {
26    let schema = Schema::build(
27        CoreQuery::<Q>::default(),
28        CoreMutation::<M>::default(),
29        EmptySubscription,
30    );
31    if let Some(app) = app {
32        schema
33            .data(
34                DataLoader::new(
35                    LedgerDataLoader {
36                        ledger: app.ledger().clone(),
37                    },
38                    tokio::task::spawn,
39                )
40                // Set delay to 0 as per https://github.com/async-graphql/async-graphql/issues/1306
41                .delay(std::time::Duration::from_secs(0)),
42            )
43            .data(app)
44            .finish()
45    } else {
46        schema.finish()
47    }
48}