Skip to content

Commit

Permalink
fix: add static data endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
sargon64 committed Jul 28, 2023
1 parent 16c1b90 commit 3dab81d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use crate::schema::{create_schema, Schema};

/// GraphiQL playground UI
async fn graphiql_route() -> Result<HttpResponse, Error> {
juniper_actix::graphiql_handler("/graphgl", None).await
juniper_actix::graphiql_handler("/graphql", None).await
}

async fn playground_route() -> Result<HttpResponse, Error> {
juniper_actix::playground_handler("/graphgl", None).await
juniper_actix::playground_handler("/graphql", None).await
}

async fn graphql_route(
Expand Down Expand Up @@ -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)),
)
Expand Down
21 changes: 20 additions & 1 deletion src/schema.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -9,6 +10,7 @@ enum Episode {
Jedi,
}

use sea_orm::EntityTrait;
use uuid::Uuid;

use crate::auth::Authorization;
Expand Down Expand Up @@ -64,6 +66,23 @@ impl QueryRoot {
async fn mod_by_author(db: &Database, id: Uuid) -> FieldResult<Vec<Mod>> {
mods::find_by_author(db, id).await
}

async fn categories(db: &Database) -> FieldResult<Vec<GCategory>> {
Ok(Categories::find().all(&db.pool).await.unwrap().iter().map(|c| GCategory {
name: c.name.clone(),
description: c.description.clone(),
}).collect::<Vec<_>>())
}

async fn beat_saber_versions(db: &Database) -> FieldResult<Vec<String>> {
Ok(BeatSaberVersions::find().all(&db.pool).await.unwrap().iter().map(|v| v.ver.clone()).collect::<Vec<_>>())
}
}

#[derive(GraphQLObject)]
pub struct GCategory {
name: String,
description: String,
}

pub type Schema =
Expand Down

0 comments on commit 3dab81d

Please sign in to comment.