use apollo_parser::cst;
use apollo_parser::Parser;
use ariadne::Label;
use ariadne::Report;
use ariadne::ReportKind;
use ariadne::Source;
use std::fs;
use std::path::Path;
fn parse_schema() -> cst::Document {
let file = Path::new("crates/apollo-parser/examples/schema_with_errors.graphql");
let src = fs::read_to_string(file).expect("Could not read schema file.");
let file_name = file
.file_name()
.expect("Could not get file name.")
.to_str()
.expect("Could not get &str from file name.");
let parser = Parser::new(&src);
let cst = parser.parse();
for err in cst.errors() {
let start = err.index();
let end = start + err.data().len();
Report::build(ReportKind::Error, (file_name, start..end))
.with_message(err.message())
.with_label(Label::new((file_name, start..end)).with_message(err.message()))
.finish()
.eprint((file_name, Source::from(&src)))
.unwrap();
}
cst.document()
}
fn main() {
parse_schema();
}