Skip to content

Commit

Permalink
feat(backend): add graphiql access (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega committed Apr 16, 2024
1 parent ac94f3a commit 536f857
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion backend/src/main.rs
@@ -1,4 +1,6 @@
use async_graphql::http::GraphiQLSource;
use dotenv::dotenv;
use rocket::response::content::RawHtml;
use std::env;
use std::ops::Deref;
use std::vec;
Expand Down Expand Up @@ -367,6 +369,11 @@ async fn graphql_request(schema: &State<AsteriaSchema>, request: Request) -> Res
request.execute(schema.deref()).await
}

#[rocket::get("/graphql")]
async fn graphiql() -> RawHtml<String> {
rocket::response::content::RawHtml(GraphiQLSource::build().endpoint("/graphql").finish())
}

#[launch]
async fn rocket() -> _ {
dotenv().ok();
Expand All @@ -387,5 +394,5 @@ async fn rocket() -> _ {

rocket::build()
.manage(schema)
.mount("/", routes![index, graphql_request])
.mount("/", routes![index, graphql_request, graphiql])
}

0 comments on commit 536f857

Please sign in to comment.