Struct apollo_compiler::diagnostic::CliReport
source · pub struct CliReport<'s> { /* private fields */ }
Expand description
A diagnostic report that can be printed to a CLI with pretty colors and labeled lines of GraphQL source code.
Custom errors can use this in their Display
or Debug
implementations to build a report and
then write it out with fmt
.
Implementations§
source§impl<'s> CliReport<'s>
impl<'s> CliReport<'s>
sourcepub fn builder(
sources: &'s SourceMap,
main_location: Option<NodeLocation>,
color: Color
) -> Self
pub fn builder( sources: &'s SourceMap, main_location: Option<NodeLocation>, color: Color ) -> Self
Returns a builder for creating diagnostic reports.
Provide GraphQL source files and the main location for the diagnostic.
Source files can be obtained from Schema::sources
or ExecutableDocument::sources
.
sourcepub fn with_message(&mut self, message: impl ToString)
pub fn with_message(&mut self, message: impl ToString)
Set the main message for the report.
sourcepub fn with_help(&mut self, help: impl ToString)
pub fn with_help(&mut self, help: impl ToString)
Set the help message for the report, usually a suggestion on how to fix the error.
sourcepub fn with_note(&mut self, note: impl ToString)
pub fn with_note(&mut self, note: impl ToString)
Set a note for the report, providing additional information that isn’t related to a source location (when a label should be used).
sourcepub fn with_label_opt(
&mut self,
location: Option<NodeLocation>,
message: impl ToString
)
pub fn with_label_opt( &mut self, location: Option<NodeLocation>, message: impl ToString )
Add a label at a given location. If the location is None
, the message is discarded.
sourcepub fn fmt(self, f: &mut Formatter<'_>) -> Result
pub fn fmt(self, f: &mut Formatter<'_>) -> Result
Write the report to a fmt::Formatter
.
sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Write the report to a new String