mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-09 00:00:12 +02:00
140 lines
4.0 KiB
Rust
140 lines
4.0 KiB
Rust
mod model;
|
|||
|
|
|
||
|
|
use async_graphql::{EmptyMutation, EmptySubscription, Schema};
|
||
|
|
use model::Episode;
|
||
|
|
use slab::Slab;
|
||
|
|
use std::collections::HashMap;
|
||
|
|
|
||
|
|
pub use model::QueryRoot;
|
||
|
|
pub type StarWarsSchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>;
|
||
|
|
|
||
|
|
pub struct StarWarsChar {
|
||
|
|
id: &'static str,
|
||
|
|
name: &'static str,
|
||
|
|
friends: Vec<usize>,
|
||
|
|
appears_in: Vec<Episode>,
|
||
|
|
home_planet: Option<&'static str>,
|
||
|
|
primary_function: Option<&'static str>,
|
||
|
|
}
|
||
|
|
|
||
|
|
pub struct StarWars {
|
||
|
|
luke: usize,
|
||
|
|
artoo: usize,
|
||
|
|
chars: Slab<StarWarsChar>,
|
||
|
|
human_data: HashMap<&'static str, usize>,
|
||
|
|
droid_data: HashMap<&'static str, usize>,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl StarWars {
|
||
|
|
#[allow(clippy::new_without_default)]
|
||
|
|
pub fn new() -> Self {
|
||
|
|
let mut chars = Slab::new();
|
||
|
|
|
||
|
|
let luke = chars.insert(StarWarsChar {
|
||
|
|
id: "1000",
|
||
|
|
name: "Luke Skywalker",
|
||
|
|
friends: vec![],
|
||
|
|
appears_in: vec![],
|
||
|
|
home_planet: Some("Tatooine"),
|
||
|
|
primary_function: None,
|
||
|
|
});
|
||
|
|
|
||
|
|
let vader = chars.insert(StarWarsChar {
|
||
|
|
id: "1001",
|
||
|
|
name: "Luke Skywalker",
|
||
|
|
friends: vec![],
|
||
|
|
appears_in: vec![],
|
||
|
|
home_planet: Some("Tatooine"),
|
||
|
|
primary_function: None,
|
||
|
|
});
|
||
|
|
|
||
|
|
let han = chars.insert(StarWarsChar {
|
||
|
|
id: "1002",
|
||
|
|
name: "Han Solo",
|
||
|
|
friends: vec![],
|
||
|
|
appears_in: vec![Episode::Empire, Episode::NewHope, Episode::Jedi],
|
||
|
|
home_planet: None,
|
||