Skip to content

Commit b43a509

Browse files
committed
Merge branch 'master' of github.com:weiznich/wundergraph
2 parents a669eaf + 5d6393f commit b43a509

File tree

8 files changed

+230
-17
lines changed

8 files changed

+230
-17
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ wundergraph::query_object!{
5656
}
5757
```
5858

59+
## Building
60+
61+
Just install some dependencies (`libsqlite3-dev` and `libpq-dev` in Debian) and `cargo build`.
62+
5963
## License
6064

6165
Licensed under either of these:

wundergraph_bench/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ num_cpus = "1.8"
2525
structopt = "0.3"
2626

2727
[features]
28-
default = []
28+
default = ["postgres"]
2929
postgres = ["wundergraph/postgres", "diesel/postgres"]
3030
sqlite = ["wundergraph/sqlite", "diesel/sqlite"]

wundergraph_cli/src/print_schema/mod.rs

+32-12
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ mod tests {
9090
id SERIAL PRIMARY KEY,
9191
author INTEGER REFERENCES infer_test.users(id),
9292
title TEXT NOT NULL,
93+
datetime TIMESTAMP,
9394
content TEXT
9495
);"#,
9596
r#"CREATE TABLE infer_test.comments(
@@ -102,17 +103,18 @@ mod tests {
102103

103104
#[cfg(feature = "sqlite")]
104105
const MIGRATION: &[&str] = &[
105-
"CREATE TABLE users(id INTEGER AUTOINCREMENT PRIMARY KEY, name TEXT NOT NULL);",
106-
r#"CREATE TABLEposts(
107-
id INTEGER AUTOINCREMENT PRIMARY KEY,
106+
"CREATE TABLE users(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL);",
107+
r#"CREATE TABLE posts(
108+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
108109
author INTEGER REFERENCES users(id),
109110
title TEXT NOT NULL,
111+
datetime TIMESTAMP,
110112
content TEXT
111113
);"#,
112-
r#"CREATE TABLE infer_test.comments(
113-
id INTEGER AUTOINCREMENT PRIMARY KEY,
114-
post INTEGER REFERENCES infer_test.posts(id),
115-
commenter INTEGER REFERENCES infer_test.users(id),
114+
r#"CREATE TABLE comments(
115+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
116+
post INTEGER REFERENCES posts(id),
117+
commenter INTEGER REFERENCES users(id),
116118
content TEXT NOT NULL
117119
);"#,
118120
];
@@ -130,7 +132,7 @@ mod tests {
130132
#[cfg(feature = "sqlite")]
131133
InferConnection::Sqlite(conn) => {
132134
for m in MIGRATION {
133-
sql_query(m).execute(conn).unwrap();
135+
sql_query(*m).execute(conn).unwrap();
134136
}
135137
}
136138
}
@@ -143,7 +145,10 @@ mod tests {
143145

144146
let mut out = Vec::<u8>::new();
145147

148+
#[cfg(feature = "postgres")]
146149
print(&conn, Some("infer_test"), &mut out).unwrap();
150+
#[cfg(feature = "sqlite")]
151+
print(&conn, None, &mut out).unwrap();
147152

148153
let s = String::from_utf8(out).unwrap();
149154
insta::assert_snapshot!(&s);
@@ -171,7 +176,10 @@ mod tests {
171176

172177
let api = tmp_dir.path().join("wundergraph_roundtrip_test/src/api.rs");
173178
let mut api_file = File::create(api).unwrap();
179+
#[cfg(feature = "postgres")]
174180
print(&conn, Some("infer_test"), &mut api_file).unwrap();
181+
#[cfg(feature = "sqlite")]
182+
print(&conn, None, &mut api_file).unwrap();
175183

176184
let main = tmp_dir
177185
.path()
@@ -196,6 +204,17 @@ mod tests {
196204
)
197205
.unwrap();
198206

207+
#[cfg(feature = "sqlite")]
208+
write!(
209+
main_file,
210+
include_str!("template_main.rs"),
211+
conn = "SqliteConnection",
212+
db_url = std::env::var("DATABASE_URL").unwrap(),
213+
migrations = migrations,
214+
listen_url = listen_url
215+
)
216+
.unwrap();
217+
199218
let cargo_toml = tmp_dir.path().join("wundergraph_roundtrip_test/Cargo.toml");
200219
let mut cargo_toml_file = std::fs::OpenOptions::new()
201220
.write(true)
@@ -210,12 +229,12 @@ mod tests {
210229
writeln!(
211230
cargo_toml_file,
212231
"{}",
213-
r#"diesel = {version = "1.4", features = ["postgres"]}"#
232+
r#"diesel = {version = "1.4", features = ["postgres", "chrono"]}"#
214233
)
215234
.unwrap();
216235
writeln!(
217236
cargo_toml_file,
218-
"wundergraph = {{path = \"{}/../wundergraph/\", features = [\"postgres\"] }}",
237+
"wundergraph = {{path = \"{}/../wundergraph/\", features = [\"postgres\", \"chrono\"] }}",
219238
current_root
220239
)
221240
.unwrap();
@@ -225,19 +244,20 @@ mod tests {
225244
writeln!(
226245
cargo_toml_file,
227246
"{}",
228-
r#"diesel = {version = "1.4", features = ["sqlite"]}"#
247+
r#"diesel = {version = "1.4", features = ["sqlite", "chrono"]}"#
229248
)
230249
.unwrap();
231250
writeln!(
232251
cargo_toml_file,
233-
"wundergraph = {{path = \"{}/../wundergraph\", features = [\"sqlite\"] }}",
252+
"wundergraph = {{path = \"{}/../wundergraph\", features = [\"sqlite\", \"chrono\"] }}",
234253
current_root
235254
)
236255
.unwrap();
237256
}
238257
writeln!(cargo_toml_file, "{}", r#"juniper = "0.14""#).unwrap();
239258
writeln!(cargo_toml_file, "{}", r#"failure = "0.1""#).unwrap();
240259
writeln!(cargo_toml_file, "{}", r#"actix-web = "1""#).unwrap();
260+
writeln!(cargo_toml_file, "{}", r#"chrono = "0.4""#).unwrap();
241261
writeln!(
242262
cargo_toml_file,
243263
"{}",

wundergraph_cli/src/print_schema/print_helper.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,16 @@ impl<'a> Display for GraphqlType<'a> {
396396
write!(f, "bool")?;
397397
}
398398
ColumnType { ref rust_name, .. } if rust_name == "Timestamptz" => {
399-
write!(f, "DateTime<Utc>")?;
399+
write!(f, "chrono::DateTime<chrono::offset::Utc>")?;
400400
}
401401
ColumnType { ref rust_name, .. } if rust_name == "Timestamp" => {
402-
write!(f, "NaiveDateTime")?;
402+
write!(f, "chrono::naive::NaiveDateTime")?;
403403
}
404404
ColumnType { ref rust_name, .. } if rust_name == "Uuid" => {
405-
write!(f, "Uuid")?;
405+
write!(f, "uuid::Uuid")?;
406406
}
407407
ColumnType { ref rust_name, .. } if rust_name == "Numeric" => {
408-
write!(f, "BigDecimal")?;
408+
write!(f, "bigdecimal::BigDecimal")?;
409409
}
410410
ColumnType { ref rust_name, .. } => write!(f, "{}", fix_table_name(rust_name))?,
411411
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
source: wundergraph_cli/src/print_schema/mod.rs
3+
expression: "r.json::<serde_json::Value>().unwrap()"
4+
---
5+
{
6+
"data": {
7+
"Users": []
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
source: wundergraph_cli/src/print_schema/mod.rs
3+
expression: "r.json::<serde_json::Value>().unwrap()"
4+
---
5+
{
6+
"errors": [
7+
{
8+
"locations": [
9+
{
10+
"column": 23,
11+
"line": 2
12+
}
13+
],
14+
"message": "Invalid value for argument \"NewUser\", expected type \"NewUser!\""
15+
}
16+
]
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
source: wundergraph_cli/src/print_schema/mod.rs
3+
expression: "r.json::<serde_json::Value>().unwrap()"
4+
---
5+
{
6+
"data": {
7+
"Users": []
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---
2+
source: wundergraph_cli/src/print_schema/mod.rs
3+
expression: "&s"
4+
---
5+
use wundergraph::query_builder::types::{HasMany, HasOne};
6+
use wundergraph::scalar::WundergraphScalarValue;
7+
use wundergraph::WundergraphEntity;
8+
9+
table! {
10+
comments (id) {
11+
id -> Integer,
12+
post -> Nullable<Integer>,
13+
commenter -> Nullable<Integer>,
14+
content -> Text,
15+
}
16+
}
17+
18+
table! {
19+
posts (id) {
20+
id -> Integer,
21+
author -> Nullable<Integer>,
22+
title -> Text,
23+
datetime -> Nullable<Timestamp>,
24+
content -> Nullable<Text>,
25+
}
26+
}
27+
28+
table! {
29+
users (id) {
30+
id -> Integer,
31+
name -> Text,
32+
}
33+
}
34+
35+
allow_tables_to_appear_in_same_query!(
36+
comments,
37+
posts,
38+
users,
39+
);
40+
41+
42+
#[derive(Clone, Debug, Identifiable, WundergraphEntity)]
43+
#[table_name = "comments"]
44+
#[primary_key(id)]
45+
pub struct Comment {
46+
id: i32,
47+
post: Option<HasOne<i32, Post>>,
48+
commenter: Option<HasOne<i32, User>>,
49+
content: String,
50+
}
51+
52+
#[derive(Clone, Debug, Identifiable, WundergraphEntity)]
53+
#[table_name = "posts"]
54+
#[primary_key(id)]
55+
pub struct Post {
56+
id: i32,
57+
author: Option<HasOne<i32, User>>,
58+
title: String,
59+
datetime: Option<chrono::naive::NaiveDateTime>,
60+
content: Option<String>,
61+
comments: HasMany<Comment, comments::post>,
62+
}
63+
64+
#[derive(Clone, Debug, Identifiable, WundergraphEntity)]
65+
#[table_name = "users"]
66+
#[primary_key(id)]
67+
pub struct User {
68+
id: i32,
69+
name: String,
70+
comments: HasMany<Comment, comments::commenter>,
71+
posts: HasMany<Post, posts::author>,
72+
}
73+
74+
75+
76+
wundergraph::query_object!{
77+
Query {
78+
Comment,
79+
Post,
80+
User,
81+
}
82+
}
83+
84+
85+
#[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)]
86+
#[graphql(scalar = "WundergraphScalarValue")]
87+
#[table_name = "comments"]
88+
pub struct NewComment {
89+
id: i32,
90+
post: Option<i32>,
91+
commenter: Option<i32>,
92+
content: String,
93+
}
94+
95+
#[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)]
96+
#[graphql(scalar = "WundergraphScalarValue")]
97+
#[table_name = "comments"]
98+
#[primary_key(id)]
99+
pub struct CommentChangeset {
100+
id: i32,
101+
post: Option<i32>,
102+
commenter: Option<i32>,
103+
content: String,
104+
}
105+
106+
#[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)]
107+
#[graphql(scalar = "WundergraphScalarValue")]
108+
#[table_name = "posts"]
109+
pub struct NewPost {
110+
id: i32,
111+
author: Option<i32>,
112+
title: String,
113+
datetime: Option<chrono::naive::NaiveDateTime>,
114+
content: Option<String>,
115+
}
116+
117+
#[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)]
118+
#[graphql(scalar = "WundergraphScalarValue")]
119+
#[table_name = "posts"]
120+
#[primary_key(id)]
121+
pub struct PostChangeset {
122+
id: i32,
123+
author: Option<i32>,
124+
title: String,
125+
datetime: Option<chrono::naive::NaiveDateTime>,
126+
content: Option<String>,
127+
}
128+
129+
#[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)]
130+
#[graphql(scalar = "WundergraphScalarValue")]
131+
#[table_name = "users"]
132+
pub struct NewUser {
133+
id: i32,
134+
name: String,
135+
}
136+
137+
#[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)]
138+
#[graphql(scalar = "WundergraphScalarValue")]
139+
#[table_name = "users"]
140+
#[primary_key(id)]
141+
pub struct UserChangeset {
142+
id: i32,
143+
name: String,
144+
}
145+
146+
wundergraph::mutation_object!{
147+
Mutation{
148+
Comment(insert = NewComment, update = CommentChangeset, ),
149+
Post(insert = NewPost, update = PostChangeset, ),
150+
User(insert = NewUser, update = UserChangeset, ),
151+
}
152+
}
153+
154+

0 commit comments

Comments
 (0)