Skip to content

Commit

Permalink
Moved schema parser to lib.rs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Mukhopadhyay committed Jul 5, 2023
1 parent 7f8515a commit dd06861
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
use graphql_parser::schema::{Document, ParseError};

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

pub fn parse_schema(schema: &str) -> Result<Document<String>, ParseError> {
graphql_parser::parse_schema::<String>(schema)
}
6 changes: 2 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use graphql_parser::parse_schema;

fn main() {
// Get the schema file from the command line arguments or use the default.
let default_schema_file = "schema.graphql".to_string();
Expand All @@ -14,7 +12,7 @@ fn main() {
}

let schema_file = result.unwrap();
let result = parse_schema::<String>(&schema_file);
let result = minigraf::parse_schema(&schema_file);
if result.is_err() {
println!("Error parsing schema file: {}", result.err().unwrap());
std::process::exit(minigraf::error_codes::ERROR_SCHEMA_INVALID);
Expand All @@ -25,5 +23,5 @@ fn main() {
}

mod error_codes {
pub const ERROR_SCHEMA_FILE_INVALID: i32 = 0x10000;
pub const ERROR_SCHEMA_FILE_INVALID: i32 = 0x100;
}

0 comments on commit dd06861

Please sign in to comment.