Skip to content

Commit 42b903f

Browse files
committed
index-node: Refactor away IndexNodeResponse
1 parent c79490b commit 42b903f

File tree

4 files changed

+2
-104
lines changed

4 files changed

+2
-104
lines changed

graph/src/components/server/query.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::data::query::QueryError;
22
use futures::prelude::*;
3-
use serde::ser::*;
43
use std::error::Error;
54
use std::fmt;
65

@@ -48,22 +47,6 @@ impl Error for GraphQLServerError {
4847
}
4948
}
5049

51-
impl Serialize for GraphQLServerError {
52-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
53-
where
54-
S: Serializer,
55-
{
56-
if let GraphQLServerError::QueryError(ref e) = *self {
57-
serializer.serialize_some(e)
58-
} else {
59-
let mut map = serializer.serialize_map(Some(1))?;
60-
let msg = format!("{}", self);
61-
map.serialize_entry("message", msg.as_str())?;
62-
map.end()
63-
}
64-
}
65-
}
66-
6750
/// Common trait for GraphQL server implementations.
6851
pub trait GraphQLServer {
6952
type ServeError;

server/index-node/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
mod request;
22
mod resolver;
3-
mod response;
43
mod schema;
54
mod server;
65
mod service;
76

87
pub use self::request::IndexNodeRequest;
9-
pub use self::response::IndexNodeResponse;
108
pub use self::server::IndexNodeServer;
119
pub use self::service::{IndexNodeService, IndexNodeServiceResponse};

server/index-node/src/response.rs

Lines changed: 0 additions & 68 deletions
This file was deleted.

server/index-node/src/service.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ use hyper::service::Service;
33
use hyper::{Body, Method, Request, Response, StatusCode};
44
use std::task::Context;
55
use std::task::Poll;
6-
use std::time::Instant;
76

87
use graph::components::server::query::GraphQLServerError;
98
use graph::prelude::*;
109
use graph_graphql::prelude::{execute_query, Query as PreparedQuery, QueryExecutionOptions};
1110

1211
use crate::request::IndexNodeRequest;
1312
use crate::resolver::IndexNodeResolver;
14-
use crate::response::IndexNodeResponse;
1513
use crate::schema::SCHEMA;
1614

1715
/// An asynchronous response to a GraphQL request.
@@ -95,14 +93,11 @@ where
9593
fn handle_graphql_query(&self, request_body: Body) -> IndexNodeServiceResponse {
9694
let logger = self.logger.clone();
9795
let store = self.store.clone();
98-
let result_logger = self.logger.clone();
9996
let graphql_runner = self.graphql_runner.clone();
10097

10198
// Obtain the schema for the index node GraphQL API
10299
let schema = SCHEMA.clone();
103100

104-
let start = Instant::now();
105-
106101
hyper::body::to_bytes(request_body)
107102
.map_err(|_| GraphQLServerError::InternalError("Failed to read request body".into()))
108103
.and_then(move |body| IndexNodeRequest::new(body, schema).compat())
@@ -128,18 +123,8 @@ where
128123
futures03::future::ok(QueryResult::from(result))
129124
})
130125
})
131-
.then(move |result| {
132-
let elapsed = start.elapsed().as_millis();
133-
if let Err(e) = &result {
134-
error!(
135-
result_logger,
136-
"GraphQL query failed";
137-
"error" => e.to_string(),
138-
"query_time_ms" => elapsed,
139-
"code" => LogCode::GraphQlQueryFailure,
140-
)
141-
}
142-
IndexNodeResponse::new(result).compat()
126+
.map_ok(|result| {
127+
result.as_http_response()
143128
})
144129
.boxed()
145130
}

0 commit comments

Comments
 (0)