Skip to content

Commit 55e5531

Browse files
committed
Fix infer_schema snapshot for sqlite
1 parent eec8b72 commit 55e5531

File tree

4 files changed

+161
-2
lines changed

4 files changed

+161
-2
lines changed

wundergraph_cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ diesel = "1.4"
1717

1818
[dev-dependencies]
1919
dotenv = "0.15"
20-
insta = "0.12"
20+
insta = "0.16"
2121
tempdir = "0.3"
2222
reqwest = "0.9"
2323
serde_json = "1"

wundergraph_cli/src/print_schema/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ mod tests {
8282
}
8383
}
8484

85+
#[cfg(feature = "postgres")]
86+
const BACKEND: &str = "postgres";
87+
88+
#[cfg(feature = "sqlite")]
89+
const BACKEND: &str = "sqlite";
90+
8591
#[cfg(feature = "postgres")]
8692
const MIGRATION: &[&str] = &[
8793
"CREATE SCHEMA infer_test;",
@@ -151,7 +157,9 @@ mod tests {
151157
print(&conn, None, &mut out).unwrap();
152158

153159
let s = String::from_utf8(out).unwrap();
154-
insta::assert_snapshot!(&s);
160+
insta::with_settings!({snapshot_suffix => BACKEND}, {
161+
insta::assert_snapshot!(&s);
162+
});
155163
}
156164

157165
#[test]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
post: Option<i32>,
90+
commenter: Option<i32>,
91+
content: String,
92+
}
93+
94+
#[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)]
95+
#[graphql(scalar = "WundergraphScalarValue")]
96+
#[table_name = "comments"]
97+
#[primary_key(id)]
98+
pub struct CommentChangeset {
99+
id: i32,
100+
post: Option<i32>,
101+
commenter: Option<i32>,
102+
content: String,
103+
}
104+
105+
#[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)]
106+
#[graphql(scalar = "WundergraphScalarValue")]
107+
#[table_name = "posts"]
108+
pub struct NewPost {
109+
author: Option<i32>,
110+
title: String,
111+
datetime: Option<chrono::naive::NaiveDateTime>,
112+
content: Option<String>,
113+
}
114+
115+
#[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)]
116+
#[graphql(scalar = "WundergraphScalarValue")]
117+
#[table_name = "posts"]
118+
#[primary_key(id)]
119+
pub struct PostChangeset {
120+
id: i32,
121+
author: Option<i32>,
122+
title: String,
123+
datetime: Option<chrono::naive::NaiveDateTime>,
124+
content: Option<String>,
125+
}
126+
127+
#[derive(Insertable, juniper::GraphQLInputObject, Clone, Debug)]
128+
#[graphql(scalar = "WundergraphScalarValue")]
129+
#[table_name = "users"]
130+
pub struct NewUser {
131+
name: String,
132+
}
133+
134+
#[derive(AsChangeset, Identifiable, juniper::GraphQLInputObject, Clone, Debug)]
135+
#[graphql(scalar = "WundergraphScalarValue")]
136+
#[table_name = "users"]
137+
#[primary_key(id)]
138+
pub struct UserChangeset {
139+
id: i32,
140+
name: String,
141+
}
142+
143+
wundergraph::mutation_object!{
144+
Mutation{
145+
Comment(insert = NewComment, update = CommentChangeset, ),
146+
Post(insert = NewPost, update = PostChangeset, ),
147+
User(insert = NewUser, update = UserChangeset, ),
148+
}
149+
}
150+
151+

0 commit comments

Comments
 (0)