Skip to content

Commit d4544f9

Browse files
committed
fix: compliance notices
1 parent 61efa93 commit d4544f9

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

docker/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ services:
2828
volumes:
2929
- ./data/ipfs:/data/ipfs
3030
postgres:
31-
image: postgres
31+
image: postgres:14
3232
ports:
3333
- '5432:5432'
3434
command:

server/http/src/service.rs

+35-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use graph::prelude::serde_json;
88
use graph::prelude::serde_json::json;
99
use graph::prelude::*;
1010
use graph::semver::VersionReq;
11+
use graph::url::form_urlencoded;
1112
use graph::{components::server::query::GraphQLServerError, data::query::QueryTarget};
1213
use http::header;
1314
use http::header::{
@@ -248,7 +249,22 @@ where
248249
}
249250
.boxed()
250251
}
252+
fn handle_mutations(&self) -> GraphQLServiceResponse {
253+
async {
254+
let response_obj = json!({
255+
"error": "Can't use mutations with GET method"
256+
});
257+
let response_str = serde_json::to_string(&response_obj).unwrap();
251258

259+
Ok(Response::builder()
260+
.status(400)
261+
.header(CONTENT_TYPE, "application/json")
262+
.header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
263+
.body(Body::from(response_str))
264+
.unwrap())
265+
}
266+
.boxed()
267+
}
252268
/// Handles requests without content type.
253269
fn handle_requests_without_content_type(&self) -> GraphQLServiceResponse {
254270
async {
@@ -275,15 +291,14 @@ where
275291
let response_str = serde_json::to_string(&response_obj).unwrap();
276292

277293
Ok(Response::builder()
278-
.status(StatusCode::BAD_REQUEST)
294+
.status(400)
279295
.header(CONTENT_TYPE, "application/json")
280296
.header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
281297
.body(Body::from(response_str))
282298
.unwrap())
283299
}
284300
.boxed()
285301
}
286-
287302
fn has_request_body(&self, req: &Request<Body>) -> bool {
288303
if let Some(length) = req.headers().get(hyper::header::CONTENT_LENGTH) {
289304
if let Ok(length) = length.to_str() {
@@ -319,6 +334,19 @@ where
319334
return self.handle_requests_without_body().boxed();
320335
}
321336

337+
let is_mutation = req
338+
.uri()
339+
.query()
340+
.and_then(|query_str| {
341+
form_urlencoded::parse(query_str.as_bytes())
342+
.find(|(key, _)| key == "query")
343+
.map(|(_, value)| value.into_owned())
344+
})
345+
.unwrap_or_else(|| String::new())
346+
.trim()
347+
.to_lowercase()
348+
.starts_with("mutation");
349+
322350
match (method, path_segments.as_slice()) {
323351
(Method::GET, [""]) => self.index().boxed(),
324352
(Method::GET, &["subgraphs", "id", _, "graphql"])
@@ -327,6 +355,9 @@ where
327355
| (Method::GET, &["subgraphs", "network", _, _, "graphql"])
328356
| (Method::GET, &["subgraphs", "graphql"]) => self.handle_graphiql(),
329357

358+
(Method::GET, path @ ["subgraphs", "name", _, _]) if is_mutation => {
359+
self.handle_mutations()
360+
}
330361
(Method::GET, path @ ["subgraphs", "id", _])
331362
| (Method::GET, path @ ["subgraphs", "name", _])
332363
| (Method::GET, path @ ["subgraphs", "name", _, _])
@@ -393,7 +424,7 @@ where
393424
let response_str = serde_json::to_string(&response_obj).unwrap();
394425

395426
Ok(Response::builder()
396-
.status(200)
427+
.status(400)
397428
.header(CONTENT_TYPE, "application/json")
398429
.header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
399430
.body(Body::from(response_str))
@@ -408,7 +439,7 @@ where
408439
let response_str = serde_json::to_string(&response_obj).unwrap();
409440

410441
Ok(Response::builder()
411-
.status(200)
442+
.status(400)
412443
.header(CONTENT_TYPE, "application/json")
413444
.header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
414445
.body(Body::from(response_str))
@@ -593,7 +624,6 @@ mod tests {
593624
.unwrap()
594625
.expect("Should return a response");
595626

596-
println!("{:?}", response);
597627
let data = test_utils::assert_successful_response(response);
598628

599629
// The body should match the simulated query result

0 commit comments

Comments
 (0)