Skip to content

Commit 983dfb4

Browse files
committed
graphql,tests: Prevent combining _logs with entity queries
1 parent 8ebc977 commit 983dfb4

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

graphql/src/execution/execution.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,15 @@ pub(crate) async fn execute_root_selection_set_uncached(
299299
}
300300
}
301301

302+
// Validate that _logs queries cannot be combined with regular entity queries
303+
if !logs_fields.is_empty() && !data_set.is_empty() {
304+
return Err(vec![QueryExecutionError::ValidationError(
305+
None,
306+
"The _logs query cannot be combined with other entity queries in the same request"
307+
.to_string(),
308+
)]);
309+
}
310+
302311
// If we are getting regular data, prefetch it from the database
303312
let (mut values, trace) = if data_set.is_empty() && meta_items.is_empty() {
304313
(Object::default(), Trace::None)

tests/tests/integration_tests.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,45 @@ async fn test_logs_query(ctx: TestContext) -> anyhow::Result<()> {
15311531
);
15321532
}
15331533

1534+
// Test 6: Verify that combining _logs with regular entity queries returns a validation error
1535+
let query = r#"{
1536+
_logs(first: 10) {
1537+
id
1538+
text
1539+
}
1540+
triggers {
1541+
id
1542+
x
1543+
}
1544+
}"#
1545+
.to_string();
1546+
let resp = subgraph.query(&query).await?;
1547+
1548+
// Should have errors, not data
1549+
assert!(
1550+
resp.get("errors").is_some(),
1551+
"Expected errors when combining _logs with entity queries, got: {:?}",
1552+
resp
1553+
);
1554+
1555+
// Verify the error message mentions the validation issue
1556+
let errors = resp["errors"]
1557+
.as_array()
1558+
.context("Expected errors to be an array")?;
1559+
assert!(
1560+
!errors.is_empty(),
1561+
"Expected at least one error in response"
1562+
);
1563+
1564+
let error_msg = errors[0]["message"]
1565+
.as_str()
1566+
.context("Expected error message to be a string")?;
1567+
assert!(
1568+
error_msg.contains("_logs") && error_msg.contains("cannot be combined"),
1569+
"Expected validation error about _logs combination, got: {}",
1570+
error_msg
1571+
);
1572+
15341573
Ok(())
15351574
}
15361575

0 commit comments

Comments
 (0)