cala_server/graphql/
mod.rs

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