File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change @@ -1425,6 +1425,45 @@ async fn test_logs_query(ctx: TestContext) -> anyhow::Result<()> {
14251425 ) ;
14261426 }
14271427
1428+ // Test 6: Verify that combining _logs with regular entity queries returns a validation error
1429+ let query = r#"{
1430+ _logs(first: 10) {
1431+ id
1432+ text
1433+ }
1434+ triggers {
1435+ id
1436+ x
1437+ }
1438+ }"#
1439+ . to_string ( ) ;
1440+ let resp = subgraph. query ( & query) . await ?;
1441+
1442+ // Should have errors, not data
1443+ assert ! (
1444+ resp. get( "errors" ) . is_some( ) ,
1445+ "Expected errors when combining _logs with entity queries, got: {:?}" ,
1446+ resp
1447+ ) ;
1448+
1449+ // Verify the error message mentions the validation issue
1450+ let errors = resp[ "errors" ]
1451+ . as_array ( )
1452+ . context ( "Expected errors to be an array" ) ?;
1453+ assert ! (
1454+ !errors. is_empty( ) ,
1455+ "Expected at least one error in response"
1456+ ) ;
1457+
1458+ let error_msg = errors[ 0 ] [ "message" ]
1459+ . as_str ( )
1460+ . context ( "Expected error message to be a string" ) ?;
1461+ assert ! (
1462+ error_msg. contains( "_logs" ) && error_msg. contains( "cannot be combined" ) ,
1463+ "Expected validation error about _logs combination, got: {}" ,
1464+ error_msg
1465+ ) ;
1466+
14281467 Ok ( ( ) )
14291468}
14301469
You can’t perform that action at this time.
0 commit comments