-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aditya Mukhopadhyay
committed
Jul 7, 2023
1 parent
ac892ee
commit be00d76
Showing
2 changed files
with
22 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters