-
Notifications
You must be signed in to change notification settings - Fork 1.1k
8000
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -132,29 +132,6 @@ impl IntoValue for Info { | |||||
| history_blocks, | ||||||
| } = self; | ||||||
|
|
||||||
| fn subgraph_error_to_value(subgraph_error: SubgraphError) -> r::Value { | ||||||
| let SubgraphError { | ||||||
| subgraph_id, | ||||||
| message, | ||||||
| block_ptr, | ||||||
| handler, | ||||||
| deterministic, | ||||||
| } = subgraph_error; | ||||||
|
|
||||||
| object! { | ||||||
| __typename: "SubgraphError", | ||||||
| subgraphId: subgraph_id.to_string(), | ||||||
| message: message, | ||||||
| handler: handler, | ||||||
| block: object! { | ||||||
| __typename: "Block", | ||||||
| number: block_ptr.as_ref().map(|x| x.number), | ||||||
| hash: block_ptr.map(|x| r::Value::from(Value::Bytes(x.hash.into()))), | ||||||
| }, | ||||||
| deterministic: deterministic, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| let non_fatal_errors: Vec<_> = non_fatal_errors | ||||||
| .into_iter() | ||||||
| .map(subgraph_error_to_value) | ||||||
|
|
@@ -176,3 +153,83 @@ impl IntoValue for Info { | |||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| fn subgraph_error_to_value(subgraph_error: SubgraphError) -> r::Value { | ||||||
| let SubgraphError { | ||||||
| subgraph_id, | ||||||
| message, | ||||||
| block_ptr, | ||||||
| handler, | ||||||
| deterministic, | ||||||
| } = subgraph_error; | ||||||
|
|
||||||
| let block_value = block_ptr | ||||||
| .map(|ptr| { | ||||||
| object! { | ||||||
| __typename: "Block", | ||||||
| number: ptr.number, | ||||||
| hash: r::Value::from(Value::Bytes(ptr.hash.into())), | ||||||
| } | ||||||
| }) | ||||||
| .unwrap_or(r::Value::Null); | ||||||
|
|
||||||
| object! { | ||||||
| __typename: "SubgraphError", | ||||||
| subgraphId: subgraph_id.to_string(), | ||||||
| message: message, | ||||||
| handler: handler, | ||||||
| block: block_value, | ||||||
| deterministic: deterministic, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| #[cfg(test)] | ||||||
| mod tests { | ||||||
| use super::*; | ||||||
| use crate::prelude::DeploymentHash; | ||||||
| use web3::types::H256; | ||||||
|
|
||||||
| #[test] | ||||||
| fn subgraph_error_block_is_null_without_pointer() { | ||||||
| let deployment = | ||||||
| DeploymentHash::new("QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco").unwrap(); | ||||||
| let value = subgraph_error_to_value(SubgraphError { | ||||||
| subgraph_id: deployment, | ||||||
| message: "boom".to_string(), | ||||||
| block_ptr: None, | ||||||
| handler: None, | ||||||
| deterministic: true, | ||||||
| }); | ||||||
|
|
||||||
| match value { | ||||||
| r::Value::Object(map) => { | ||||||
| assert_eq!(map.get("block"), Some(&r::Value::Null)); | ||||||
| } | ||||||
| _ => panic!("expected object"), | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| #[test] | ||||||
| fn subgraph_error_block_contains_data_when_present() { | ||||||
| let deployment = | ||||||
| DeploymentHash::new("QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco").unwrap(); | ||||||
| let ptr = BlockPtr::new(H256::zero().into(), 42); | ||||||
| let value = subgraph_error_to_value(SubgraphError { | ||||||
| subgraph_id: deployment, | ||||||
| message: "boom".to_string(), | ||||||
| block_ptr: Some(ptr), | ||||||
| handler: None, | ||||||
| deterministic: true, | ||||||
| }); | ||||||
|
|
||||||
| match value { | ||||||
| r::Value::Object(map) => match map.get("block").expect("block field present") { | ||||||
| r::Value::Object(block) => { | ||||||
| assert_eq!(block.get("number"), Some(&r::Value::Int(42.into()))); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This unit test asserts
Suggested change
|
||||||
| } | ||||||
| other => panic!("unexpected block value {other:?}"), | ||||||
| }, | ||||||
| _ => panic!("expected object"), | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block.numberis aBigInt!in the index-node GraphQL schema and elsewhere in the codebaseBlockPtrserializesnumberas a string (e.g.,format!("{}", self.number)). Here it’s emitted as anInt(ptr.number), which is inconsistent and can break clients/serde deserialization expecting the BigInt string form. Consider reusingBlockPtr’sIntoValueimplementation (or at least format the number as a string) for schema-consistent output.