Skip to content

Commit d611928

Browse files
committed
Include depth info in SelectionSetTooDeep error
Change ValidationError::SelectionSetTooDeep from a single Pos variant to a struct containing depth, max_depth, and pos. Update OperationValidator to return the new struct, adjust pattern matches to destructure the new variant, and update validation snapshots and an integration test to expect the more informative error message (includes actual and allowed depths).
1 parent 77f1ef8 commit d611928

6 files changed

Lines changed: 28 additions & 14 deletions

File tree

crates/core-subsystem/core-resolver/src/validation/operation_validator.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ impl<'a> OperationValidator<'a> {
7474
self.normal_query_depth_limit
7575
};
7676
if depth > max_depth {
77-
Err(ValidationError::SelectionSetTooDeep(pos))
77+
Err(ValidationError::SelectionSetTooDeep {
78+
depth,
79+
max_depth,
80+
pos,
81+
})
7882
} else {
7983
Ok(true)
8084
}

crates/core-subsystem/core-resolver/src/validation/snapshots/introspection_query_depth_limit_direct-2.snap

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ source: crates/core-subsystem/core-resolver/src/validation/document_validator.rs
33
expression: validator.validate(create_query_document(query))
44
---
55
Err(
6-
SelectionSetTooDeep(
7-
Pos(5:25),
8-
),
6+
SelectionSetTooDeep {
7+
depth: 3,
8+
max_depth: 2,
9+
pos: Pos(5:25),
10+
},
911
)

crates/core-subsystem/core-resolver/src/validation/snapshots/query_depth_limit_direct-2.snap

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ source: crates/core-subsystem/core-resolver/src/validation/document_validator.rs
33
expression: validator.validate(create_query_document(query))
44
---
55
Err(
6-
SelectionSetTooDeep(
7-
Pos(8:37),
8-
),
6+
SelectionSetTooDeep {
7+
depth: 6,
8+
max_depth: 5,
9+
pos: Pos(8:37),
10+
},
911
)

crates/core-subsystem/core-resolver/src/validation/snapshots/query_depth_limit_through_fragment-2.snap

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ source: crates/core-subsystem/core-resolver/src/validation/document_validator.rs
33
expression: validator.validate(create_query_document(query))
44
---
55
Err(
6-
SelectionSetTooDeep(
7-
Pos(14:25),
8-
),
6+
SelectionSetTooDeep {
7+
depth: 6,
8+
max_depth: 5,
9+
pos: Pos(14:25),
10+
},
911
)

crates/core-subsystem/core-resolver/src/validation/validation_error.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ pub enum ValidationError {
7272
#[error("Fragment cycle detected: {0}")]
7373
FragmentCycle(String, Pos),
7474

75-
#[error("Selection set too deep")]
76-
SelectionSetTooDeep(Pos),
75+
#[error("Selection set depth {depth} exceeds the maximum allowed depth {max_depth}")]
76+
SelectionSetTooDeep {
77+
depth: usize,
78+
max_depth: usize,
79+
pos: Pos,
80+
},
7781

7882
#[error("Invalid value for '{value_name}': {range_detail}, {value_detail}")]
7983
ValueOutOfRange {
@@ -106,7 +110,7 @@ impl ValidationError {
106110
ValidationError::MultipleOperationsUnmatchedOperationName(_) => vec![],
107111
ValidationError::InvalidArgumentType { pos, .. } => vec![*pos],
108112
ValidationError::FragmentCycle(_, pos) => vec![*pos],
109-
ValidationError::SelectionSetTooDeep(pos) => vec![*pos],
113+
ValidationError::SelectionSetTooDeep { pos, .. } => vec![*pos],
110114
ValidationError::ValueOutOfRange { pos, .. } => vec![*pos],
111115
}
112116
}

integration-tests/error-reporting/tests/over-the-limit-query-depth.exotest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ response: |
2323
{
2424
"errors": [
2525
{
26-
"message": "Selection set too deep",
26+
"message": "Selection set depth 6 exceeds the maximum allowed depth 5",
2727
"locations": [
2828
{
2929
"line": 11,

0 commit comments

Comments
 (0)