diff --git a/src/main.rs b/src/main.rs index 0a8b349..883198b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,11 +20,11 @@ use crate::schema::{create_schema, Schema}; /// GraphiQL playground UI async fn graphiql_route() -> Result { - juniper_actix::graphiql_handler("/graphgl", None).await + juniper_actix::graphiql_handler("/graphql", None).await } async fn playground_route() -> Result { - juniper_actix::playground_handler("/graphgl", None).await + juniper_actix::playground_handler("/graphql", None).await } async fn graphql_route( @@ -97,7 +97,7 @@ async fn main() -> io::Result<()> { pool: db_conn.clone(), })) .service( - web::resource("/graphgl") + web::resource("/graphql") .route(web::post().to(graphql_route)) .route(web::get().to(graphql_route)), ) diff --git a/src/schema.rs b/src/schema.rs index e8a7cd2..0a38408 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -1,5 +1,6 @@ +use entity::prelude::*; use juniper::{ - graphql_value, EmptyMutation, EmptySubscription, FieldResult, GraphQLEnum, RootNode, + graphql_value, EmptyMutation, EmptySubscription, FieldResult, GraphQLEnum, RootNode, GraphQLObject, }; #[derive(GraphQLEnum)] @@ -9,6 +10,7 @@ enum Episode { Jedi, } +use sea_orm::EntityTrait; use uuid::Uuid; use crate::auth::Authorization; @@ -64,6 +66,23 @@ impl QueryRoot { async fn mod_by_author(db: &Database, id: Uuid) -> FieldResult> { mods::find_by_author(db, id).await } + + async fn categories(db: &Database) -> FieldResult> { + Ok(Categories::find().all(&db.pool).await.unwrap().iter().map(|c| GCategory { + name: c.name.clone(), + description: c.description.clone(), + }).collect::>()) + } + + async fn beat_saber_versions(db: &Database) -> FieldResult> { + Ok(BeatSaberVersions::find().all(&db.pool).await.unwrap().iter().map(|v| v.ver.clone()).collect::>()) + } +} + +#[derive(GraphQLObject)] +pub struct GCategory { + name: String, + description: String, } pub type Schema =