use std::marker::PhantomData; use juniper::{ EmptyMutation, EmptySubscription, ID, RootNode, graphql_object, GraphQLObject, GraphQLEnum, }; use sqlx::{ SqlitePool, types::chrono::{ DateTime, Utc, }, }; use url::Url; #[derive(Clone, Copy, Debug)] pub struct Context<'db> { db: &'db SqlitePool, } impl<'db> juniper::Context for Context<'db> {} #[derive(Clone, Debug, GraphQLObject)] pub struct User { id: ID, user_name: String, display_name: Option, activated: bool, created: DateTime, last_online: Option>, preferences: UserPreferences, } #[derive(Clone, Debug, GraphQLObject)] pub struct UserPreferences { privacy_preferences: PrivacyPreferences, notification_preferences: NotificationPreferences, security_preferences: SecurityPreferences, external_servers_preferences: ExternalServersPreferences, } #[derive(Clone, Debug, GraphQLObject)] pub struct PrivacyPreferences { discovery: RestrictionPolicy, discovery_user_limit: Option>, discovery_server_limit: Option>, last_seen: RestrictionPolicy, last_seen_user_limit: Option>, last_seen_server_limit: Option>, last_seen_course: bool, info: RestrictionPolicy, info_user_limit: Option>, info_server_limit: Option>, } #[derive(Clone, Copy, Debug, GraphQLObject)] pub struct NotificationPreferences { lock_details: bool, do_not_disturb: bool, } #[derive(Clone, Debug, GraphQLObject)] pub struct SecurityPreferences { account_tokens: Vec, password_hash: String, } #[derive(Clone, Debug, GraphQLObject)] pub struct ExternalServersPreferences { privacy_preferences: PrivacyPreferences, external_servers: RestrictionPolicy, external_servers_limit: Option>, } #[derive(Clone, Copy, Debug, GraphQLEnum)] pub enum RestrictionPolicy { Everyone, Excluding, Including, None, } #[derive(Clone, Copy, Debug)] pub struct Query<'db> { phantom: PhantomData<&'db ()>, } #[graphql_object(context = Context<'db>)] impl<'db> Query<'db> { async fn users(context: &Context<'db>) -> Vec { unimplemented!() } } pub type Schema<'root_node, 'db> = RootNode<'root_node, Query<'db>, EmptyMutation>, EmptySubscription>>; pub fn schema<'root_node, 'db>() -> Schema<'root_node, 'db> { Schema::new(Query { phantom: PhantomData, }, EmptyMutation::new(), EmptySubscription::new()) }