2021-07-21 10:23:14 +02:00
|
|
|
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<String>,
|
|
|
|
activated: bool,
|
|
|
|
created: DateTime<Utc>,
|
|
|
|
last_online: Option<DateTime<Utc>>,
|
|
|
|
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<Vec<String>>,
|
|
|
|
discovery_server_limit: Option<Vec<Url>>,
|
|
|
|
last_seen: RestrictionPolicy,
|
|
|
|
last_seen_user_limit: Option<Vec<String>>,
|
|
|
|
last_seen_server_limit: Option<Vec<Url>>,
|
|
|
|
last_seen_course: bool,
|
|
|
|
info: RestrictionPolicy,
|
|
|
|
info_user_limit: Option<Vec<String>>,
|
|
|
|
info_server_limit: Option<Vec<Url>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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<ID>,
|
|
|
|
password_hash: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, GraphQLObject)]
|
|
|
|
pub struct ExternalServersPreferences {
|
|
|
|
privacy_preferences: PrivacyPreferences,
|
|
|
|
external_servers: RestrictionPolicy,
|
|
|
|
external_servers_limit: Option<Vec<Url>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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<User> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type Schema<'root_node, 'db> = RootNode<'root_node, Query<'db>, EmptyMutation<Context<'db>>, EmptySubscription<Context<'db>>>;
|
|
|
|
|
|
|
|
pub fn schema<'root_node, 'db>() -> Schema<'root_node, 'db> {
|
|
|
|
Schema::new(Query {
|
|
|
|
phantom: PhantomData,
|
|
|
|
}, EmptyMutation::new(), EmptySubscription::new())
|
|
|
|
}
|