Skip to content

Commit

Permalink
fix: block constraint rewrite fallbacks (#764)
Browse files Browse the repository at this point in the history
# Release Notes
- fix: inefficiencies in processing Agora contexts (#747, #752, dbc5a0b,
e4ebfe5)
  • Loading branch information
Theodus authored May 22, 2024
1 parent 7c3452d commit 48c8922
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions graph-gateway/src/block_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,26 +182,29 @@ pub fn rewrite_query<'q>(
.find(|(n, _)| *n == "block")
.and_then(|(_, field)| field_constraint(&ctx.variables, defaults, field).ok())
{
match constraint {
BlockConstraint::Hash(hash) => {
write!(buf, "{{ hash: \"{hash}\" }}").unwrap()
match (constraint, &latest_block) {
(BlockConstraint::Hash(hash), _) => {
write!(buf, "{{ hash: \"{hash}\" }}").unwrap();
}
BlockConstraint::Number(number) => {
(BlockConstraint::Number(number), _) => {
match chain.find(&UnresolvedBlock::WithNumber(number)) {
Some(Block { hash, .. }) => {
write!(buf, "{{ hash: \"{hash}\" }}").unwrap()
write!(buf, "{{ hash: \"{hash}\" }}").unwrap();
}
None => write!(buf, "{{ number: {number} }}").unwrap(),
}
}
BlockConstraint::Unconstrained | BlockConstraint::NumberGTE(_) => {
match &latest_block {
Some(Block { hash, .. }) => {
write!(buf, "{{ hash: \"{hash}\" }}").unwrap()
None => {
write!(buf, "{{ number: {number} }}").unwrap();
}
None => write!(buf, "{{}}").unwrap(),
}
}
(_, Some(Block { hash, .. })) => {
write!(buf, "{{ hash: \"{hash}\" }}",).unwrap();
}
(BlockConstraint::NumberGTE(number), None) => {
write!(buf, "{{ number_gte: {number} }}").unwrap();
}
(BlockConstraint::Unconstrained, None) => {
write!(buf, "null").unwrap();
}
};
} else if let Some(block) = &latest_block {
write!(buf, "{{ hash: \"{}\" }}", block.hash).unwrap();
Expand Down Expand Up @@ -517,6 +520,15 @@ mod tests {
},
"{\n bundle0: bundle(block: { number: 125 }, id: \"1\") {\n ethPriceUSD\n }\n _gateway_probe_: _meta { block { hash number timestamp } }\n}\n",
),
(
r#"{ bundle(block:{number_gte:125}) { ethPriceUSD } }"#,
BlockRequirements {
latest: true,
number_gte: Some(125),
range: None,
},
"{\n bundle(block: { number_gte: 125 }) {\n ethPriceUSD\n }\n _gateway_probe_: _meta { block { hash number timestamp } }\n}\n",
),
(
r#"query GetTopSales {
events(where: { type: "Sale" }, first: 1, orderBy: value, orderDirection: desc) {
Expand Down

0 comments on commit 48c8922

Please sign in to comment.