38 lines
780 B
Rust
38 lines
780 B
Rust
use dataloader::non_cached::Loader;
|
|
use juniper::FieldResult;
|
|
use juniper::IntoFieldError;
|
|
|
|
use crate::{
|
|
api::{loaders, Error},
|
|
db,
|
|
};
|
|
|
|
#[derive(Clone)]
|
|
pub struct Loaders {
|
|
pub directory: loaders::directory::DirectoryLoader,
|
|
}
|
|
|
|
impl Default for Loaders {
|
|
fn default() -> Self {
|
|
Self {
|
|
directory: Loader::new(loaders::directory::DirectoryBatcher)
|
|
.with_yield_count(loaders::directory::YIELD_COUNT),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct Context {
|
|
pub db_pool: db::Pool,
|
|
pub loaders: Loaders,
|
|
}
|
|
|
|
impl Context {
|
|
pub fn get_db_conn(&self) -> FieldResult<db::PoolConnection> {
|
|
self.db_pool
|
|
.get()
|
|
.map_or(Err(Error::Internal.into_field_error()), Ok)
|
|
}
|
|
}
|
|
|
|
impl juniper::Context for Context {}
|