Skip to content

Commit

Permalink
Read schema from a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Mukhopadhyay committed Jul 5, 2023
1 parent af1f3e3 commit 05ae359
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/target
/Cargo.lock
/schema.graphql

.idea
14 changes: 14 additions & 0 deletions schema.graphql.example
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!,
}
28 changes: 10 additions & 18 deletions src/main.rs
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);
}

0 comments on commit 05ae359

Please sign in to comment.