Skip to content

Commit 84c8d5f

Browse files
feat(compiler): add compact Debug impl for LineColumn (#910)
This felt nicer in a case like the below: https://github.com/apollographql/router/blob/e9dc61255e87294f624a0ecc68ac7c83fab5a7f0/apollo-federation/src/sources/connect/validation/snapshots/validation_tests%40rest.graphql.snap#L10-L25 It's not a big deal though. If anyone isn't that enthusiastic about it we can just not :)
1 parent 50abfaf commit 84c8d5f

File tree

3 files changed

+17
-41
lines changed

3 files changed

+17
-41
lines changed

crates/apollo-compiler/src/parser.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub struct SourceSpan {
6868
}
6969

7070
/// A line number and column number within a GraphQL document.
71-
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize)]
71+
#[derive(Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize)]
7272
#[serde(deny_unknown_fields)]
7373
pub struct LineColumn {
7474
/// The line number for this location, starting at 1 for the first line.
@@ -78,6 +78,12 @@ pub struct LineColumn {
7878
pub column: usize,
7979
}
8080

81+
impl std::fmt::Debug for LineColumn {
82+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
83+
write!(f, "{}:{}", self.line, self.column)
84+
}
85+
}
86+
8187
/// Parse a schema and executable document from the given source text
8288
/// containing a mixture of type system definitions and executable definitions.
8389
/// and validate them.

crates/apollo-compiler/tests/introspection_max_depth.rs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ fn test_3_nested_fields_lists() {
6666
GraphQLError {
6767
message: "Maximum introspection depth exceeded",
6868
locations: [
69-
LineColumn {
70-
line: 8,
71-
column: 19,
72-
},
69+
8:19,
7370
],
7471
path: [],
7572
extensions: {},
@@ -120,10 +117,7 @@ fn test_3_nested_input_fields_lists() {
120117
GraphQLError {
121118
message: "Maximum introspection depth exceeded",
122119
locations: [
123-
LineColumn {
124-
line: 8,
125-
column: 19,
126-
},
120+
8:19,
127121
],
128122
path: [],
129123
extensions: {},
@@ -172,10 +166,7 @@ fn test_3_nested_interfaces_lists() {
172166
GraphQLError {
173167
message: "Maximum introspection depth exceeded",
174168
locations: [
175-
LineColumn {
176-
line: 7,
177-
column: 17,
178-
},
169+
7:17,
179170
],
180171
path: [],
181172
extensions: {},
@@ -224,10 +215,7 @@ fn test_3_nested_possible_types_lists() {
224215
GraphQLError {
225216
message: "Maximum introspection depth exceeded",
226217
locations: [
227-
LineColumn {
228-
line: 7,
229-
column: 17,
230-
},
218+
7:17,
231219
],
232220
path: [],
233221
extensions: {},
@@ -294,10 +282,7 @@ fn test_3_nested_possible_types_lists_with_inline_fragments() {
294282
GraphQLError {
295283
message: "Maximum introspection depth exceeded",
296284
locations: [
297-
LineColumn {
298-
line: 11,
299-
column: 25,
300-
},
285+
11:25,
301286
],
302287
path: [],
303288
extensions: {},
@@ -367,10 +352,7 @@ fn test_3_nested_possible_types_lists_with_named_fragments() {
367352
GraphQLError {
368353
message: "Maximum introspection depth exceeded",
369354
locations: [
370-
LineColumn {
371-
line: 20,
372-
column: 9,
373-
},
355+
20:9,
374356
],
375357
path: [],
376358
extensions: {},

crates/apollo-compiler/tests/introspection_split.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ fn test_nested() {
7878
GraphQLError {
7979
message: "Schema introspection field __schema is not supported nested in other fields",
8080
locations: [
81-
LineColumn {
82-
line: 2,
83-
column: 43,
84-
},
81+
2:43,
8582
],
8683
path: [],
8784
extensions: {},
@@ -100,10 +97,7 @@ fn test_nested_in_fragment() {
10097
GraphQLError {
10198
message: "Schema introspection field __schema is not supported nested in other fields",
10299
locations: [
103-
LineColumn {
104-
line: 3,
105-
column: 41,
106-
},
100+
3:41,
107101
],
108102
path: [],
109103
extensions: {},
@@ -121,10 +115,7 @@ fn test_mutation() {
121115
GraphQLError {
122116
message: "Schema introspection field __schema is not supported in a mutation operation",
123117
locations: [
124-
LineColumn {
125-
line: 2,
126-
column: 33,
127-
},
118+
2:33,
128119
],
129120
path: [],
130121
extensions: {},
@@ -142,10 +133,7 @@ fn test_mutation_nested() {
142133
GraphQLError {
143134
message: "Schema introspection field __schema is not supported in a mutation operation",
144135
locations: [
145-
LineColumn {
146-
line: 2,
147-
column: 46,
148-
},
136+
2:46,
149137
],
150138
path: [],
151139
extensions: {},

0 commit comments

Comments
 (0)