Skip to content

Commit 628db34

Browse files
committed
Add error message when using GET for /graphql
Graphql expects a POST request so warn when client uses GET.
1 parent 0e6ebab commit 628db34

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::error;
22

33
use async_graphql::{EmptyMutation, EmptySubscription, Schema};
44
use axum::http::StatusCode;
5-
use axum::response::Html;
5+
use axum::response::{Html, IntoResponse};
66
use axum::routing::{get, post};
77
use axum::{Extension, Router};
88

@@ -57,6 +57,7 @@ async fn serve(config: GlazedConfig) -> Result<(), Box<dyn error::Error>> {
5757

5858
let app = Router::new()
5959
.route("/graphql", post(graphql_handler))
60+
.route("/graphql", get(graphql_get_warning))
6061
.route("/graphiql", get(graphiql_handler))
6162
.fallback((
6263
StatusCode::NOT_FOUND,
@@ -72,6 +73,14 @@ async fn serve(config: GlazedConfig) -> Result<(), Box<dyn error::Error>> {
7273
.await?)
7374
}
7475

76+
async fn graphql_get_warning() -> impl IntoResponse {
77+
(
78+
StatusCode::METHOD_NOT_ALLOWED,
79+
[("Allow", "POST")],
80+
Html(include_str!("../static/get_graphql_warning.html")),
81+
)
82+
}
83+
7584
async fn signal_handler() {
7685
let mut term = signal(SignalKind::terminate()).expect("Failed to create SIGTERM listener");
7786
let mut int = signal(SignalKind::interrupt()).expect("Failed to create SIGINT listener");

static/get_graphql_warning.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Glazed</title>
5+
</head>
6+
<body>
7+
<p>Requests should be made as graphql queries</p>
8+
</body>
9+
</html>

0 commit comments

Comments
 (0)