-
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 5, 2023
1 parent
af1f3e3
commit 05ae359
Showing
3 changed files
with
25 additions
and
18 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,4 +1,5 @@ | ||
/target | ||
/Cargo.lock | ||
/schema.graphql | ||
|
||
.idea |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
schema { | ||
query: Query | ||
} | ||
type Query { | ||
users: [User!]!, | ||
} | ||
""" | ||
Example user object | ||
|
||
This is just a demo comment. | ||
""" | ||
type User { | ||
name: String!, | ||
} |
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,24 +1,16 @@ | ||
use std::io; | ||
use std::io::Write; | ||
|
||
use graphql_parser::query::parse_query; | ||
use graphql_parser::parse_schema; | ||
|
||
fn main() { | ||
loop { | ||
// Prompt user | ||
print!("> "); | ||
io::stdout().flush().unwrap(); | ||
// Get the schema file from the command line arguments or use the default. | ||
let default_schema_file = "schema.graphql".to_string(); | ||
let schema_file = &std::env::args().nth(1).unwrap_or(default_schema_file); | ||
|
||
// Read input from stdin | ||
let mut input = String::new(); | ||
io::stdin().read_line(&mut input).unwrap(); | ||
let input = input.trim(); | ||
println!("schema_file: {}", schema_file); | ||
|
||
// Parse input | ||
let ast = parse_query::<&str>(input); | ||
// Read the schema file and parse it into a schema object. | ||
let schema_file = std::fs::read_to_string(schema_file).unwrap(); | ||
|
||
println!("{:#?}", ast); | ||
} | ||
} | ||
let ast = parse_schema::<String>(&schema_file).unwrap().to_owned(); | ||
|
||
// fn run() {} | ||
println!("{:#?}", ast); | ||
} |