This commit is contained in:
41666 2022-12-07 00:01:38 -05:00
parent 1f2e3e6eab
commit 5c3a9a1888
11 changed files with 950 additions and 253 deletions

View file

@ -8,10 +8,11 @@ edition = "2021"
[dependencies]
redis = { version = "0.22.1", features = ["aio", "r2d2", "tokio-comp"] }
serde_json = "1.0.89"
serde = "1.0.148"
serde = "1.0.149"
async-graphql = { version = "5.0.2" }
async-graphql-axum = "5.0.2"
axum = "0.6.0"
tokio = { version = "1.22.0" }
tower-http = { version = "0.3.4", features = ["cors"] }
axum = "0.6.1"
sqlx = { version = "0.6.2", features = [ "runtime-tokio-native-tls" , "postgres" ] }
tokio = { version = "1.23.0", features = [ "full" ] }
tower-http = { version = "0.3.5", features = ["cors"] }
lazy_static = "1.4.0"

View file

@ -6,8 +6,7 @@ mod vehicles;
mod world;
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
EmptyMutation, EmptySubscription, Request, Response, Schema,
http::GraphiQLSource, EmptyMutation, EmptySubscription, Request, Response, Schema,
};
use axum::{
extract::Query,
@ -42,13 +41,19 @@ async fn graphql_handler_get(
query: Query<Request>,
) -> axum::response::Response {
if query.query == "" {
return Redirect::to("/graphql/playground").into_response();
return Redirect::to("/graphiql").into_response();
}
Json(schema.execute(query.0).await).into_response()
}
async fn graphql_playground() -> impl IntoResponse {
Html(playground_source(GraphQLPlaygroundConfig::new("/graphql")))
async fn graphiql() -> impl IntoResponse {
Html(
GraphiQLSource::build()
.endpoint("/graphql")
.title("Saerro Listening Post")
.finish(),
)
}
#[tokio::main]
@ -76,7 +81,7 @@ async fn main() {
"/graphql",
post(graphql_handler_post).get(graphql_handler_get),
)
.route("/graphql/playground", get(graphql_playground))
.route("/graphql/playground", get(graphiql))
.fallback(handle_404)
.layer(Extension(redis))
.layer(Extension(schema))