Skip to content

Commit

Permalink
fix(server/http): graphql server compliance issues (#4507)
Browse files Browse the repository at this point in the history
* fix(server/http): graphql server compliance issues
  • Loading branch information
YassinEldeeb committed Jul 25, 2023
1 parent 1535e24 commit e0d90c2
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 33 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ lcov.info
# Built solidity contracts.
/tests/**/bin
/tests/**/truffle_output

# Docker volumes and debug logs
.postgres
logfile
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ services:
volumes:
- ./data/ipfs:/data/ipfs
postgres:
image: postgres
image: postgres:14
ports:
- '5432:5432'
command:
Expand Down
2 changes: 2 additions & 0 deletions graph/src/data/query/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ impl QueryResults {

pub fn as_http_response<T: From<String>>(&self) -> http::Response<T> {
let status_code = http::StatusCode::OK;

let json =
serde_json::to_string(self).expect("Failed to serialize GraphQL response to JSON");

http::Response::builder()
.status(status_code)
.header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
Expand Down
11 changes: 7 additions & 4 deletions server/http/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::net::{Ipv4Addr, SocketAddrV4};

use futures::future::Future;
use hyper::service::make_service_fn;
use hyper::Server;
use thiserror::Error;

use crate::service::GraphQLService;
use graph::prelude::{GraphQLServer as GraphQLServerTrait, *};
use thiserror::Error;
use graph::prelude::{GraphQLServer as GraphQLServerTrait, GraphQlRunner, *};

/// Errors that may occur when starting the server.
#[derive(Debug, Error)]
Expand Down Expand Up @@ -66,12 +67,14 @@ where
let graphql_runner = self.graphql_runner.clone();
let node_id = self.node_id.clone();
let new_service = make_service_fn(move |_| {
futures03::future::ok::<_, Error>(GraphQLService::new(
let graphql_service = GraphQLService::new(
logger_for_service.clone(),
graphql_runner.clone(),
ws_port,
node_id.clone(),
))
);

futures03::future::ok::<_, Error>(graphql_service)
});

// Create a task to run the server and handle HTTP requests
Expand Down
Loading

0 comments on commit e0d90c2

Please sign in to comment.