Skip to content

Commit 84ab990

Browse files
committed
graph, server/index-node: Fix parsing GraphQL block hashes/numbers
This fixes the following error when querying the index node server: failed to parse subgraph deployments: Invalid character 'x' at position
1 parent 62b0f58 commit 84ab990

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

graph/src/data/graphql/values.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use graphql_parser::query::{Name, Value};
33
use std::collections::{BTreeMap, HashMap};
44
use std::str::FromStr;
55

6-
use crate::prelude::format_err;
6+
use crate::prelude::{format_err, BigInt};
77
use web3::types::{H160, H256};
88

99
pub trait TryFromValue: Sized {
@@ -84,6 +84,19 @@ impl TryFromValue for H256 {
8484
}
8585
}
8686

87+
impl TryFromValue for BigInt {
88+
fn try_from_value(value: &Value) -> Result<Self, Error> {
89+
match value {
90+
Value::String(s) => BigInt::from_str(s)
91+
.map_err(|e| format_err!("Cannot parse BigInt value from string `{}`: {}", s, e)),
92+
_ => Err(format_err!(
93+
"Cannot parse value into an BigInt: {:?}",
94+
value
95+
)),
96+
}
97+
}
98+
}
99+
87100
impl<T> TryFromValue for Vec<T>
88101
where
89102
T: TryFromValue,

server/index-node/src/resolver.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use graphql_parser::{query as q, query::Name, schema as s, schema::ObjectType};
22
use std::collections::{BTreeMap, HashMap};
3-
use std::str::FromStr;
43

54
use graph::data::graphql::{TryFromValue, ValueList, ValueMap};
65
use graph::data::subgraph::schema::SUBGRAPHS_ID;
@@ -149,22 +148,9 @@ impl IndexingStatusWithoutNode {
149148
let number_key = format!("{}Number", prefix);
150149

151150
match (
151+
value.get_optional::<H256>(hash_key.as_ref())?,
152152
value
153-
.get_optional::<q::Value>(hash_key.as_ref())?
154-
.and_then(|value| match value {
155-
q::Value::String(s) => Some(s),
156-
_ => None,
157-
})
158-
.map(|s| H256::from_str(s.as_ref()))
159-
.transpose()?,
160-
value
161-
.get_optional::<q::Value>(number_key.as_ref())?
162-
.and_then(|value| match value {
163-
q::Value::String(s) => Some(s),
164-
_ => None,
165-
})
166-
.map(|s| BigInt::from_str(s.as_ref()))
167-
.transpose()?
153+
.get_optional::<BigInt>(number_key.as_ref())?
168154
.map(|n| n.to_u64()),
169155
) {
170156
// Only return an Ethereum block if we can parse both the block hash and number

0 commit comments

Comments
 (0)