forked from graphprotocol/graph-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.rs
More file actions
67 lines (59 loc) · 1.83 KB
/
Copy pathrunner.rs
File metadata and controls
67 lines (59 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use futures::future;
use std::env;
use std::str::FromStr;
use std::time::{Duration, Instant};
use graph::prelude::{GraphQlRunner as GraphQlRunnerTrait, *};
use graph_graphql::prelude::*;
use lazy_static::lazy_static;
/// GraphQL runner implementation for The Graph.
pub struct GraphQlRunner<S> {
logger: Logger,
store: Arc<S>,
}
lazy_static! {
static ref GRAPHQL_QUERY_TIMEOUT: Option<Duration> = env::var("GRAPH_GRAPHQL_QUERY_TIMEOUT")
.ok()
.map(|s| Duration::from_secs(
u64::from_str(&s)
.unwrap_or_else(|_| panic!("failed to parse env var GRAPH_GRAPHQL_QUERY_TIMEOUT"))
));
}
impl<S> GraphQlRunner<S>
where
S: Store,
{
/// Creates a new query runner.
pub fn new(logger: &Logger, store: Arc<S>) -> Self {
GraphQlRunner {
logger: logger.new(o!("component" => "GraphQlRunner")),
store,
}
}
}
impl<S> GraphQlRunnerTrait for GraphQlRunner<S>
where
S: Store,
{
fn run_query(&self, query: Query) -> QueryResultFuture {
let result = execute_query(
&query,
QueryExecutionOptions {
logger: self.logger.clone(),
resolver: StoreResolver::new(&self.logger, self.store.clone()),
deadline: GRAPHQL_QUERY_TIMEOUT.map(|t| Instant::now() + t),
},
);
Box::new(future::ok(result))
}
fn run_subscription(&self, subscription: Subscription) -> SubscriptionResultFuture {
let result = execute_subscription(
&subscription,
SubscriptionExecutionOptions {
logger: self.logger.clone(),
resolver: StoreResolver::new(&self.logger, self.store.clone()),
timeout: GRAPHQL_QUERY_TIMEOUT.clone(),
},
);
Box::new(future::result(result))
}
}