76 lines
1.3 KiB
Rust
76 lines
1.3 KiB
Rust
use juniper::{graphql_object, EmptyMutation, EmptySubscription, FieldResult, RootNode};
|
|
|
|
use crate::config;
|
|
use crate::db;
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct Context {
|
|
pub pool: db::DbPool,
|
|
}
|
|
|
|
impl juniper::Context for Context {}
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct Config;
|
|
|
|
#[graphql_object(context = Context)]
|
|
impl Config {
|
|
fn name(&self) -> &str {
|
|
"BVplan"
|
|
}
|
|
|
|
fn school(&self) -> &str {
|
|
&config::CONFIG.untis_school
|
|
}
|
|
|
|
fn version(&self) -> &str {
|
|
env!("CARGO_PKG_VERSION")
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct Teacher {
|
|
pub id: i32,
|
|
pub display_name: String,
|
|
}
|
|
|
|
#[graphql_object(context = Context)]
|
|
impl Teacher {
|
|
fn id(&self) -> i32 {
|
|
self.id
|
|
}
|
|
|
|
fn display_name(&self) -> &str {
|
|
&self.display_name
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
pub struct Query;
|
|
|
|
#[graphql_object(context = Context)]
|
|
impl Query {
|
|
fn ping() -> &str {
|
|
"pong"
|
|
}
|
|
|
|
fn config() -> Config {
|
|
Config
|
|
}
|
|
|
|
async fn teachers() -> Vec<Teacher> {
|
|
vec![]
|
|
}
|
|
}
|
|
|
|
pub type Schema = RootNode<'static, Query, EmptyMutation<Context>, EmptySubscription<Context>>;
|
|
|
|
pub fn schema() -> Schema {
|
|
Schema::new(
|
|
Query,
|
|
EmptyMutation::<Context>::new(),
|
|
EmptySubscription::<Context>::new(),
|
|
)
|
|
}
|