Skip to content

Commit

Permalink
Schema and query parsers in lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Mukhopadhyay committed Jul 7, 2023
1 parent ac892ee commit be00d76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
24 changes: 21 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
use graphql_parser::schema::{Document, ParseError};
use graphql_parser::query;
use graphql_parser::schema;

pub mod error_codes {
pub const ERROR_SCHEMA_INVALID: i32 = 1;
pub const ERROR_QUERY_INVALID: i32 = 2;
}

pub fn parse_schema(schema: &str) -> Result<Document<String>, ParseError> {
graphql_parser::parse_schema::<String>(schema)
pub fn load_schema(schema: &str) -> schema::Document<String> {
let schema = schema::parse_schema::<String>(schema).unwrap_or_else(|err| {
eprintln!("Error parsing schema: {}", err);
std::process::exit(error_codes::ERROR_SCHEMA_INVALID);
});
dbg!("schema: {:#?}", &schema);

schema
}

pub fn parse_query(query: &str) -> query::Document<String> {
let query = query::parse_query::<String>(query).unwrap_or_else(|err| {
eprintln!("Error parsing query: {}", err);
std::process::exit(error_codes::ERROR_QUERY_INVALID);
});
dbg!("query: {:#?}", &query);

query
}
6 changes: 1 addition & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ fn main() {
process::exit(error_codes::ERROR_SCHEMA_FILE_INVALID);
});

let schema = minigraf::parse_schema(&schema_file).unwrap_or_else(|err| {
eprintln!("Error parsing schema file: {}", err);
process::exit(minigraf::error_codes::ERROR_SCHEMA_INVALID);
});
dbg!("schema: {:#?}", schema);
minigraf::load_schema(&schema_file);
}

mod error_codes {
Expand Down

0 comments on commit be00d76

Please sign in to comment.