Skip to content

run round_trip's assertions in separate threads #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 5, 2020
2 changes: 1 addition & 1 deletion wundergraph_cli/src/infer_schema_internals/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ fn load_table_names_returns_error_when_given_schema_name() {
let table_names = load_table_names(&conn, Some("stuff"));
match table_names {
Ok(_) => panic!("Expected load_table_names to return an error"),
Err(e) => assert!(e.description().starts_with(
Err(e) => assert!(e.to_string().starts_with(
"sqlite cannot infer \
schema for databases"
)),
Expand Down
58 changes: 29 additions & 29 deletions wundergraph_cli/src/print_schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,41 +311,41 @@ mod tests {
std::thread::sleep(std::time::Duration::from_secs(1));

let query = "{\"query\": \"{ Users { id name } } \"}";
let mut r = client
.post(&format!("http://{}/graphql", listen_url))
.body(query)
.header(
reqwest::header::CONTENT_TYPE,
reqwest::header::HeaderValue::from_static("application/json"),
)
.send()
.unwrap();
insta::assert_json_snapshot!(r.json::<serde_json::Value>().unwrap());

let mutation = r#"{"query":"mutation CreateUser {\n CreateUser(NewUser: {name: \"Max\"}) {\n id\n name\n }\n}","variables":null,"operationName":"CreateUser"}"#;
let mut r = client
.post(&format!("http://{}/graphql", listen_url))
.body(mutation)
.header(
reqwest::header::CONTENT_TYPE,
reqwest::header::HeaderValue::from_static("application/json"),
)
.send()
.unwrap();
insta::assert_json_snapshot!(r.json::<serde_json::Value>().unwrap());
let t1 = request_test(&client, &listen_url, query);
let t2 = request_test(&client, &listen_url, mutation);
let t3 = request_test(&client, &listen_url, query);

child.kill().unwrap();
child.wait().unwrap();

if t1.is_err() || t2.is_err() || t3.is_err() {
panic!("round_trip failed")
}
}

let mut r = client
fn request_test(
client: &reqwest::Client,
listen_url: &str,
body: &'static str,
) -> Result<(), std::string::String> {
let r = client
.post(&format!("http://{}/graphql", listen_url))
.body(query)
.body(body)
.header(
reqwest::header::CONTENT_TYPE,
reqwest::header::HeaderValue::from_static("application/json"),
)
.send()
.unwrap();
insta::assert_json_snapshot!(r.json::<serde_json::Value>().unwrap());

child.kill().unwrap();
child.wait().unwrap();
.send();
match r {
Ok(mut r) => match r.json::<serde_json::Value>() {
Ok(r) => match std::panic::catch_unwind(|| insta::assert_json_snapshot!(r)) {
Ok(_) => Ok(()),
Err(e) => Err(format!("{:?}", e)),
},
Err(e) => Err(format!("{:?}", e)),
},
Err(e) => Err(format!("{:?}", e)),
}
}
}
11 changes: 10 additions & 1 deletion wundergraph_cli/src/print_schema/print_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,16 @@ impl<'a> Display for GraphqlInsertable<'a> {
{
let mut out = PadAdapter::new(f);
writeln!(out)?;
for c in self.table.column_data.iter().filter(|c| !c.has_default) {
for c in self.table.column_data.iter().filter(|c| {
!c.has_default
&& self
.table
.primary_key
.iter()
.filter(|x| **x == c.sql_name)
.count()
== 0
}) {
let t = GraphqlType {
sql_type: &c.ty,
allow_option: true,
Expand Down
3 changes: 0 additions & 3 deletions wundergraph_cli/src/print_schema/snapshots/tests__main.snap
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ wundergraph::query_object!{
#[graphql(scalar = "WundergraphScalarValue")]
#[table_name = "comments"]
pub struct NewComment {
id: i32,
post: Option<i32>,
commenter: Option<i32>,
content: String,
Expand All @@ -107,7 +106,6 @@ pub struct CommentChangeset {
#[graphql(scalar = "WundergraphScalarValue")]
#[table_name = "posts"]
pub struct NewPost {
id: i32,
author: Option<i32>,
title: String,
datetime: Option<chrono::naive::NaiveDateTime>,
Expand All @@ -130,7 +128,6 @@ pub struct PostChangeset {
#[graphql(scalar = "WundergraphScalarValue")]
#[table_name = "users"]
pub struct NewUser {
id: i32,
name: String,
}

Expand Down