Skip to content

Commit 52397a2

Browse files
author
Alexei Pastuchov
committed
add mysql branch for infer_schema test
1 parent b91ba4d commit 52397a2

File tree

2 files changed

+166
-7
lines changed

2 files changed

+166
-7
lines changed

wundergraph_cli/src/print_schema/mod.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,22 @@ mod tests {
169169

170170
let mut out = Vec::<u8>::new();
171171

172-
#[cfg(feature = "postgres")]
173-
print(&conn, Some("infer_test"), &mut out).unwrap();
174-
#[cfg(any(feature = "mysql", feature = "sqlite"))]
175-
print(&conn, None, &mut out).unwrap();
176-
177-
let s = String::from_utf8(out).unwrap();
178-
insta::assert_snapshot!(&s);
172+
if cfg!(feature = "mysql") {
173+
print(&conn, None, &mut out).unwrap();
174+
let mut settings = insta::Settings::clone_current();
175+
let s = String::from_utf8(out).unwrap();
176+
settings.set_snapshot_suffix("mysql");
177+
settings.bind(|| {
178+
insta::assert_snapshot!(&s);
179+
});
180+
} else {
181+
#[cfg(feature = "postgres")]
182+
print(&conn, Some("infer_test"), &mut out).unwrap();
183+
#[cfg(feature = "sqlite")]
184+
print(&conn, None, &mut out).unwrap();
185+
let s = String::from_utf8(out).unwrap();
186+
insta::assert_snapshot!(&s);
187+
}
179188
}
180189

181190
#[test]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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 -> 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<i32>,
48+
commenter: Option<i32>,
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<i32>,
58+
title: String,
59+
datetime: chrono::naive::NaiveDateTime,
60+
content: Option<String>,
61+
}
62+
63+
#[derive(Clone, Debug, Identifiable, WundergraphEntity)]
64+
#[table_name = "users"]
65+
#[primary_key(id)]
66+
pub struct User {
67+
id: i32,
68+
name: String,
69+
}
70+
71+
72+
73+
wundergraph::query_object!{
74+
Query {
75+
Comment,
76+
Post,
77+
User,
78+
}
79+
}
80+
81+
82+
#[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)]
83+
#[graphql(scalar = "WundergraphScalarValue")]
84+
#[table_name = "comments"]
85+
pub struct NewComment {
86+
id: i32,
87+
post: Option<i32>,
88+
commenter: Option<i32>,
89+
content: String,
90+
}
91+
92+
#[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)]
93+
#[graphql(scalar = "WundergraphScalarValue")]
94+
#[table_name = "comments"]
95+
#[primary_key(id)]
96+
pub struct CommentChangeset {
97+
id: i32,
98+
post: Option<i32>,
99+
commenter: Option<i32>,
100+
content: String,
101+
}
102+
103+
#[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)]
104+
#[graphql(scalar = "WundergraphScalarValue")]
105+
#[table_name = "posts"]
106+
pub struct NewPost {
107+
id: i32,
108+
author: Option<i32>,
109+
title: String,
110+
content: Option<String>,
111+
}
112+
113+
#[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)]
114+
#[graphql(scalar = "WundergraphScalarValue")]
115+
#[table_name = "posts"]
116+
#[primary_key(id)]
117+
pub struct PostChangeset {
118+
id: i32,
119+
author: Option<i32>,
120+
title: String,
121+
datetime: chrono::naive::NaiveDateTime,
122+
content: Option<String>,
123+
}
124+
125+
#[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)]
126+
#[graphql(scalar = "WundergraphScalarValue")]
127+
#[table_name = "users"]
128+
pub struct NewUser {
129+
id: i32,
130+
name: String,
131+
}
132+
133+
#[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)]
134+
#[graphql(scalar = "WundergraphScalarValue")]
135+
#[table_name = "users"]
136+
#[primary_key(id)]
137+
pub struct UserChangeset {
138+
id: i32,
139+
name: String,
140+
}
141+
142+
wundergraph::mutation_object!{
143+
Mutation{
144+
Comment(insert = NewComment, update = CommentChangeset, ),
145+
Post(insert = NewPost, update = PostChangeset, ),
146+
User(insert = NewUser, update = UserChangeset, ),
147+
}
148+
}
149+
150+

0 commit comments

Comments
 (0)