Skip to content

Commit 5801629

Browse files
committed
Convert schema meta to GraphQL schema
1 parent c2af491 commit 5801629

File tree

7 files changed

+559
-22
lines changed

7 files changed

+559
-22
lines changed

.github/workflows/tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ jobs:
220220
- name: Additional Integration tests
221221
working-directory: ./examples/postgres
222222
run: |
223-
cargo test --test query_array_tests
224-
rm tests/query_array_tests.rs
223+
cargo test --test query_array_tests entity_metadata_tests
224+
rm tests/query_array_tests.rs tests/entity_metadata_tests.rs
225225
- name: Remove generated folder
226226
run: rm -rf ./examples/postgres/src
227227
- name: Generate entities

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ heck = { version = "0.4.1" }
2727
thiserror = { version = "1.0.44" }
2828
fnv = { version = "1.0.7" }
2929
lazy_static = { version = "1.5" }
30+
serde = { version = "1.0", optional = true }
3031
serde_json = { version = "1.0" }
3132
pluralizer = { version = "0.5", optional = true }
3233

3334
[features]
34-
default = ["field-camel-case"]
35+
default = ["field-camel-case", "schema-meta"]
3536
macros = ["seaography-macros"]
37+
schema-meta = ["macros", "serde/derive", "with-postgres-array"]
3638
rbac = ["sea-orm/rbac"]
3739
with-json = ["sea-orm/with-json"]
3840
with-chrono = ["sea-orm/with-chrono", "async-graphql/chrono"]

examples/postgres/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ tracing-subscriber = { version = "0.3.17" }
1515
[dependencies.seaography]
1616
path = "../../"
1717
version = "~2.0.0-rc.1" # seaography version
18-
features = ["with-decimal", "with-chrono", "with-postgres-array"]
18+
features = ["with-decimal", "with-chrono", "with-postgres-array", "schema-meta"]
1919

2020
[dev-dependencies]
2121
serde_json = { version = "1.0.103" }
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
use async_graphql::{dynamic::*, Response};
2+
use sea_orm::Database;
3+
use seaography::async_graphql;
4+
5+
pub async fn get_schema() -> Schema {
6+
let database = Database::connect("postgres://sea:[email protected]/sakila")
7+
.await
8+
.unwrap();
9+
let schema = seaography_postgres_example::query_root::schema(database, None, None).unwrap();
10+
11+
schema
12+
}
13+
14+
pub fn assert_eq(a: Response, b: &str) {
15+
assert_eq!(
16+
a.data.into_json().unwrap(),
17+
serde_json::from_str::<serde_json::Value>(b).unwrap()
18+
)
19+
}
20+
21+
#[tokio::test]
22+
async fn test_entity_metadata() {
23+
let schema = get_schema().await;
24+
25+
assert_eq(
26+
schema
27+
.execute(
28+
r#"{
29+
city: _sea_orm_entity_metadata(table_name: "city") {
30+
columns {
31+
name
32+
nullable
33+
type_ {
34+
primitive
35+
array {
36+
array {
37+
primitive
38+
}
39+
}
40+
enumeration {
41+
name
42+
variants
43+
}
44+
}
45+
}
46+
primary_key
47+
}
48+
film: _sea_orm_entity_metadata(table_name: "film") {
49+
columns {
50+
name
51+
nullable
52+
type_ {
53+
primitive
54+
array {
55+
array {
56+
primitive
57+
}
58+
}
59+
enumeration {
60+
name
61+
variants
62+
}
63+
}
64+
}
65+
primary_key
66+
}
67+
}
68+
"#,
69+
)
70+
.await,
71+
r#"
72+
{
73+
"city": {
74+
"columns": [
75+
{
76+
"name": "city_id",
77+
"nullable": false,
78+
"type_": {
79+
"primitive": "integer",
80+
"array": null,
81+
"enumeration": null
82+
}
83+
},
84+
{
85+
"name": "city",
86+
"nullable": false,
87+
"type_": {
88+
"primitive": "string",
89+
"array": null,
90+
"enumeration": null
91+
}
92+
},
93+
{
94+
"name": "country_id",
95+
"nullable": false,
96+
"type_": {
97+
"primitive": "integer",
98+
"array": null,
99+
"enumeration": null
100+
}
101+
},
102+
{
103+
"name": "last_update",
104+
"nullable": false,
105+
"type_": {
106+
"primitive": "datetime",
107+
"array": null,
108+
"enumeration": null
109+
}
110+
}
111+
],
112+
"primary_key": [
113+
"city_id"
114+
]
115+
},
116+
"film": {
117+
"columns": [
118+
{
119+
"name": "film_id",
120+
"nullable": false,
121+
"type_": {
122+
"primitive": "integer",
123+
"array": null,
124+
"enumeration": null
125+
}
126+
},
127+
{
128+
"name": "title",
129+
"nullable": false,
130+
"type_": {
131+
"primitive": "string",
132+
"array": null,
133+
"enumeration": null
134+
}
135+
},
136+
{
137+
"name": "description",
138+
"nullable": true,
139+
"type_": {
140+
"primitive": "string",
141+
"array": null,
142+
"enumeration": null
143+
}
144+
},
145+
{
146+
"name": "release_year",
147+
"nullable": true,
148+
"type_": {
149+
"primitive": "integer",
150+
"array": null,
151+
"enumeration": null
152+
}
153+
},
154+
{
155+
"name": "language_id",
156+
"nullable": false,
157+
"type_": {
158+
"primitive": "integer",
159+
"array": null,
160+
"enumeration": null
161+
}
162+
},
163+
{
164+
"name": "original_language_id",
165+
"nullable": true,
166+
"type_": {
167+
"primitive": "integer",
168+
"array": null,
169+
"enumeration": null
170+
}
171+
},
172+
{
173+
"name": "rental_duration",
174+
"nullable": false,
175+
"type_": {
176+
"primitive": "integer",
177+
"array": null,
178+
"enumeration": null
179+
}
180+
},
181+
{
182+
"name": "rental_rate",
183+
"nullable": false,
184+
"type_": {
185+
"primitive": "decimal",
186+
"array": null,
187+
"enumeration": null
188+
}
189+
},
190+
{
191+
"name": "length",
192+
"nullable": true,
193+
"type_": {
194+
"primitive": "integer",
195+
"array": null,
196+
"enumeration": null
197+
}
198+
},
199+
{
200+
"name": "replacement_cost",
201+
"nullable": false,
202+
"type_": {
203+
"primitive": "decimal",
204+
"array": null,
205+
"enumeration": null
206+
}
207+
},
208+
{
209+
"name": "rating",
210+
"nullable": true,
211+
"type_": {
212+
"primitive": null,
213+
"array": null,
214+
"enumeration": {
215+
"name": "mpaa_rating",
216+
"variants": [
217+
"G",
218+
"NC-17",
219+
"PG",
220+
"PG-13",
221+
"R"
222+
]
223+
}
224+
}
225+
},
226+
{
227+
"name": "last_update",
228+
"nullable": false,
229+
"type_": {
230+
"primitive": "datetime",
231+
"array": null,
232+
"enumeration": null
233+
}
234+
},
235+
{
236+
"name": "special_features",
237+
"nullable": true,
238+
"type_": {
239+
"primitive": null,
240+
"array": {
241+
"array": {
242+
"primitive": "string"
243+
}
244+
},
245+
"enumeration": null
246+
}
247+
}
248+
],
249+
"primary_key": [
250+
"film_id"
251+
]
252+
}
253+
}
254+
"#,
255+
)
256+
}

0 commit comments

Comments
 (0)