Skip to content

Commit a77d583

Browse files
p-alikweiznich
authored and
Alexei Pastuchov
committed
Update wundergraph_cli/src/print_schema/snapshots/[email protected]
Co-authored-by: Georg Semmler <[email protected]>
1 parent 52397a2 commit a77d583

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

wundergraph_cli/src/print_schema/mod.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,28 @@ mod tests {
121121

122122
#[cfg(feature = "mysql")]
123123
const MIGRATION: &[&str] = &[
124-
"CREATE TABLE users(id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, name TEXT NOT NULL);",
124+
r#"CREATE TABLE users(
125+
id INTEGER NOT NULL AUTO_INCREMENT,
126+
name TEXT NOT NULL,
127+
PRIMARY KEY (`id`)
128+
);"#,
125129
r#"CREATE TABLE posts(
126-
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
127-
author INTEGER REFERENCES users(id),
130+
id INTEGER NOT NULL AUTO_INCREMENT,
131+
author INTEGER DEFAULT NULL,
128132
title TEXT NOT NULL,
129-
datetime TIMESTAMP,
130-
content TEXT
133+
datetime TIMESTAMP NULL DEFAULT NULL,
134+
content TEXT,
135+
PRIMARY KEY (`id`),
136+
FOREIGN KEY (`author`) REFERENCES `users` (`id`)
131137
);"#,
132138
r#"CREATE TABLE comments(
133-
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
134-
post INTEGER REFERENCES posts(id),
135-
commenter INTEGER REFERENCES users(id),
136-
content TEXT NOT NULL
139+
id INTEGER NOT NULL AUTO_INCREMENT,
140+
post INTEGER DEFAULT NULL,
141+
commenter INTEGER DEFAULT NULL,
142+
content TEXT NOT NULL,
143+
PRIMARY KEY (`id`),
144+
FOREIGN KEY (`post`) REFERENCES `posts` (`id`),
145+
FOREIGN KEY (`commenter`) REFERENCES `users` (`id`)
137146
);"#,
138147
];
139148

wundergraph_cli/src/print_schema/snapshots/[email protected]

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ table! {
2020
id -> Integer,
2121
author -> Nullable<Integer>,
2222
title -> Text,
23-
datetime -> Timestamp,
23+
datetime -> Nullable<Timestamp>,
2424
content -> Nullable<Text>,
2525
}
2626
}
@@ -44,8 +44,8 @@ allow_tables_to_appear_in_same_query!(
4444
#[primary_key(id)]
4545
pub struct Comment {
4646
id: i32,
47-
post: Option<i32>,
48-
commenter: Option<i32>,
47+
post: Option<HasOne<i32, Post>>,
48+
commenter: Option<HasOne<i32, User>>,
4949
content: String,
5050
}
5151

@@ -54,10 +54,11 @@ pub struct Comment {
5454
#[primary_key(id)]
5555
pub struct Post {
5656
id: i32,
57-
author: Option<i32>,
57+
author: Option<HasOne<i32, User>>,
5858
title: String,
59-
datetime: chrono::naive::NaiveDateTime,
59+
datetime: Option<chrono::naive::NaiveDateTime>,
6060
content: Option<String>,
61+
comments: HasMany<Comment, comments::post>,
6162
}
6263

6364
#[derive(Clone, Debug, Identifiable, WundergraphEntity)]
@@ -66,6 +67,8 @@ pub struct Post {
6667
pub struct User {
6768
id: i32,
6869
name: String,
70+
comments: HasMany<Comment, comments::commenter>,
71+
posts: HasMany<Post, posts::author>,
6972
}
7073

7174

@@ -83,7 +86,6 @@ wundergraph::query_object!{
8386
#[graphql(scalar = "WundergraphScalarValue")]
8487
#[table_name = "comments"]
8588
pub struct NewComment {
86-
id: i32,
8789
post: Option<i32>,
8890
commenter: Option<i32>,
8991
content: String,
@@ -104,9 +106,9 @@ pub struct CommentChangeset {
104106
#[graphql(scalar = "WundergraphScalarValue")]
105107
#[table_name = "posts"]
106108
pub struct NewPost {
107-
id: i32,
108109
author: Option<i32>,
109110
title: String,
111+
datetime: Option<chrono::naive::NaiveDateTime>,
110112
content: Option<String>,
111113
}
112114

@@ -118,15 +120,14 @@ pub struct PostChangeset {
118120
id: i32,
119121
author: Option<i32>,
120122
title: String,
121-
datetime: chrono::naive::NaiveDateTime,
123+
datetime: Option<chrono::naive::NaiveDateTime>,
122124
content: Option<String>,
123125
}
124126

125127
#[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)]
126128
#[graphql(scalar = "WundergraphScalarValue")]
127129
#[table_name = "users"]
128130
pub struct NewUser {
129-
id: i32,
130131
name: String,
131132
}
132133

@@ -147,4 +148,3 @@ wundergraph::mutation_object!{
147148
}
148149
}
149150

150-

0 commit comments

Comments
 (0)