Use a cargo workspace for better modularity

Currently, there is only a `gateway` crate, but in the future,
likely more will be added to handle db stuff, abstractions, etc once
I actually start implementing the city portal logic itself.
This commit is contained in:
Zeph Levy 2025-10-19 14:43:18 +02:00
parent b2384d2e76
commit 4faedce5c6
8 changed files with 157 additions and 214 deletions

View file

@ -1,44 +1,3 @@
mod models;
mod resolvers;
mod schema;
use async_graphql_axum::{GraphQLRequest, GraphQLResponse};
use axum::{
Router,
routing::{get, post},
};
use schema::build_schema;
use std::net::SocketAddr;
#[tokio::main]
async fn main() {
let schema = build_schema();
let app = Router::new()
.route(
"/graphql",
post({
let schema = schema.clone();
move |req: GraphQLRequest| async move {
GraphQLResponse::from(schema.execute(req.into_inner()).await)
}
}),
)
.route(
"/graphql",
get({
let schema = schema.clone();
move || async move { axum::Json(schema.sdl()) }
}),
);
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
println!("listening on http://{}", addr);
axum::serve(
tokio::net::TcpListener::bind(addr).await.unwrap(),
app.into_make_service(),
)
.await
.unwrap();
fn main() {
gateway::start();
}

View file

@ -1,7 +0,0 @@
use async_graphql::SimpleObject;
#[derive(SimpleObject)]
pub struct User {
pub id: i32,
pub name: String,
}

View file

@ -1,22 +0,0 @@
use crate::models::User;
use async_graphql::Object;
pub struct QueryRoot;
#[Object]
impl QueryRoot {
async fn hello(&self) -> &str {
"Hello, world!"
}
async fn testing(&self) -> &str {
"Testing"
}
async fn user(&self, id: i32) -> User {
User {
id,
name: String::from("Zeph"),
}
}
}

View file

@ -1,8 +0,0 @@
use crate::resolvers::QueryRoot;
use async_graphql::{EmptyMutation, EmptySubscription, Schema};
pub type AppSchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>;
pub fn build_schema() -> AppSchema {
Schema::build(QueryRoot, EmptyMutation, EmptySubscription).finish()
}