1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use crate::GraphQLErrorNoteKind;
use crate::SourceSpan;
/// An error note providing additional context about an error.
///
/// Notes augment the primary error message with:
/// - Explanatory context (why the error occurred)
/// - Actionable suggestions (how to fix it)
/// - Specification references (where to learn more)
/// - Related source locations (e.g., where a delimiter was opened)
#[derive(Debug, Clone, PartialEq)]
pub struct GraphQLErrorNote {
/// The kind of note (determines rendering prefix).
pub kind: GraphQLErrorNoteKind,
/// The note message.
pub message: String,
/// Optional pre-resolved span pointing to a related location.
///
/// When present, the note is rendered with a source snippet
/// pointing to this location. Like the primary error's
/// `source_span`, this is eagerly resolved at error
/// construction time so it carries line/column/byte-offset
/// information without requiring a `SourceMap` at display time.
pub span: Option<SourceSpan>,
}
impl GraphQLErrorNote {
/// Creates a general note without a span.
pub fn general(message: impl Into<String>) -> Self {
Self {
kind: GraphQLErrorNoteKind::General,
message: message.into(),
span: None,
}
}
/// Creates a general note with a pre-resolved span.
pub fn general_with_span(
message: impl Into<String>,
span: SourceSpan,
) -> Self {
Self {
kind: GraphQLErrorNoteKind::General,
message: message.into(),
span: Some(span),
}
}
/// Creates a help note without a span.
pub fn help(message: impl Into<String>) -> Self {
Self {
kind: GraphQLErrorNoteKind::Help,
message: message.into(),
span: None,
}
}
/// Creates a help note with a pre-resolved span.
pub fn help_with_span(
message: impl Into<String>,
span: SourceSpan,
) -> Self {
Self {
kind: GraphQLErrorNoteKind::Help,
message: message.into(),
span: Some(span),
}
}
/// Creates a spec reference note.
pub fn spec(url: impl Into<String>) -> Self {
Self {
kind: GraphQLErrorNoteKind::Spec,
message: url.into(),
span: None,
}
}
}