use async_graphql::{Context, EmptyMutation, EmptySubscription, Object, Schema, SimpleObject}; use uuid::Uuid; pub type CibusSchema = Schema; pub struct QueryRoot; #[Object] impl QueryRoot { async fn get_upcoming(&self, ctx: &Context<'_>) -> Vec { vec![Event::new( None, "Some-name".into(), None, None, EventDate::new(2022, 08, 08, 23, 51), )] } } #[derive(SimpleObject)] pub struct Event { pub id: String, pub name: String, pub description: Option>, pub location: Option, pub date: EventDate, } impl Event { pub fn new( id: Option, name: String, description: Option>, location: Option, date: EventDate, ) -> Self { Self { id: id.unwrap_or_else(|| Uuid::new_v4().to_string()), name, description, location, date, } } } #[derive(SimpleObject)] pub struct EventDate { pub year: u32, pub month: u32, pub day: u32, pub hour: u32, pub minute: u32, } impl EventDate { pub fn new(year: u32, month: u32, day: u32, hour: u32, minute: u32) -> Self { Self { year, month, day, hour, minute, } } }