use std::collections::HashMap;
use std::convert::TryFrom;
use warpgrapher::engine::config::Configuration;
use warpgrapher::engine::context::RequestContext;
use warpgrapher::engine::database::cypher::CypherEndpoint;
use warpgrapher::engine::database::DatabaseEndpoint;
use warpgrapher::Engine;
static CONFIG: &str = "
version: 1
model:
- name: User
props:
- name: email
type: String
required: false
";
#[derive(Clone, Debug)]
struct AppRequestContext {}
impl RequestContext for AppRequestContext {
type DBEndpointType = CypherEndpoint;
fn new() -> AppRequestContext {
AppRequestContext {}
}
}
#[tokio::main]
async fn main() {
let config = Configuration::try_from(CONFIG.to_string()).expect("Failed to parse CONFIG");
let db = CypherEndpoint::from_env()
.expect("Failed to parse cypher endpoint from environment")
.pool()
.await
.expect("Failed to create cypher database pool");
let engine: Engine<AppRequestContext> = Engine::new(config, db)
.build()
.expect("Failed to build engine");
let query = "
mutation {
UserCreate(input: {
email: \"a@b.com\"
}) {
id
email
}
}
"
.to_string();
let metadata = HashMap::new();
let result = engine.execute(query, None, metadata).await.unwrap();
println!("result: {:#?}", result);
}