diff --git a/src/handlers/graphql.rs b/src/handlers/graphql.rs index 2791d04..4fde46d 100644 --- a/src/handlers/graphql.rs +++ b/src/handlers/graphql.rs @@ -1,6 +1,8 @@ +use async_graphql::http::GraphiQLSource; use async_graphql::*; use async_graphql_axum::{GraphQLRequest, GraphQLResponse}; use axum::Extension; +use axum::response::{Html, IntoResponse}; use crate::clients::Client; use crate::schemas::TiledQuery; @@ -14,6 +16,10 @@ pub async fn graphql_handler( schema.execute(query).await.into() } +pub async fn graphiql_handler() -> impl IntoResponse { + Html(GraphiQLSource::build().endpoint("/graphql").finish()) +} + #[cfg(test)] mod tests { use async_graphql::{EmptyMutation, EmptySubscription, Schema}; diff --git a/src/main.rs b/src/main.rs index 9b9e3a3..22ddd4e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use std::error; use async_graphql::{EmptyMutation, EmptySubscription, Schema}; -use axum::routing::post; +use axum::routing::{get, post}; use axum::{Extension, Router}; mod cli; @@ -14,7 +14,7 @@ use cli::{Cli, Commands}; use crate::clients::tiled_client::TiledClient; use crate::config::GlazedConfig; -use crate::handlers::graphql::graphql_handler; +use crate::handlers::graphql::{graphiql_handler, graphql_handler}; use crate::schemas::TiledQuery; #[tokio::main] @@ -42,6 +42,7 @@ async fn serve(config: GlazedConfig) -> Result<(), Box> { let app = Router::new() .route("/graphql", post(graphql_handler::)) + .route("/graphiql", get(graphiql_handler)) .layer(Extension(schema)); let listener = tokio::net::TcpListener::bind(config.bind_address).await?;