Skip to content

Commit 3f71f44

Browse files
committed
add bad way to dump schema, add schema
1 parent bc124c2 commit 3f71f44

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,6 @@ tokio-scoped = "0.2.0"
6363
[target.'cfg(all(target_env = "musl", target_pointer_width = "64"))'.dependencies.mimalloc]
6464
version = "0.1"
6565
default-features = false
66+
67+
[features]
68+
dump-schema = []

src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ async fn refresh<'a>() -> Response {
8080
.unwrap()
8181
}
8282

83+
#[cfg(not(feature = "dump-schema"))]
8384
#[tokio::main(flavor = "current_thread")]
8485
async fn main() {
8586
CACHE
@@ -138,3 +139,10 @@ async fn main() {
138139
.await
139140
.unwrap_or_else(|e| panic!("failed to run `axum::serve`: {e}"));
140141
}
142+
143+
#[cfg(feature = "dump-schema")]
144+
fn main() {
145+
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
146+
std::fs::write("ucsc_menu.graphql", schema.as_sdl().as_bytes())
147+
.expect("error writing schema to file");
148+
}

ucsc_menu.graphql

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
schema {
2+
query: Query
3+
}
4+
5+
enum Allergens {
6+
EGG
7+
FISH
8+
GLUTEN_FRIENDLY
9+
MILK
10+
PEANUT
11+
SOY
12+
TREE_NUT
13+
ALCOHOL
14+
VEGAN
15+
VEGETARIAN
16+
PORK
17+
BEEF
18+
HALAL
19+
SHELLFISH
20+
SESAME
21+
}
22+
23+
enum Type {
24+
BREAKFAST
25+
LUNCH
26+
DINNER
27+
LATE_NIGHT
28+
MENU
29+
UNKNOWN
30+
ALL_DAY
31+
BANANA_JOES
32+
}
33+
34+
input DateRange {
35+
start: Date
36+
end: Date
37+
}
38+
39+
"""
40+
Date in the proleptic Gregorian calendar (without time zone).
41+
42+
Represents a description of the date (as used for birthdays, for example).
43+
It cannot represent an instant on the time-line.
44+
45+
[`Date` scalar][1] compliant.
46+
47+
See also [`chrono::NaiveDate`][2] for details.
48+
49+
[1]: https://graphql-scalars.dev/docs/scalars/date
50+
[2]: https://docs.rs/chrono/latest/chrono/naive/struct.NaiveDate.html
51+
"""
52+
scalar Date
53+
54+
type DailyMenu {
55+
date: Date!
56+
meals(mealType: Type): [Meal!]!
57+
}
58+
59+
type FoodItem {
60+
allergens: [Allergens!]!
61+
name: String!
62+
price: String
63+
}
64+
65+
type Location {
66+
id: String!
67+
name: String!
68+
menus(dateRange: DateRange): [DailyMenu!]!
69+
}
70+
71+
type Locations {
72+
locations(ids: [String!]): [Location!]!
73+
}
74+
75+
type Meal {
76+
mealType: Type!
77+
sections: [Section!]!
78+
}
79+
80+
type Query {
81+
"Adds two `a` and `b` numbers."
82+
query: Locations!
83+
}
84+
85+
type Section {
86+
name: String!
87+
foodItems(containsAllAllergens: [Allergens!], excludesAllAllergens: [Allergens!], containsAnyAllergens: [Allergens!], nameContains: String): [FoodItem!]!
88+
}

0 commit comments

Comments
 (0)