Implement user object for graphql
This commit is contained in:
parent
e294adcacd
commit
cb83a386dc
11 changed files with 159 additions and 36 deletions
77
Cargo.lock
generated
77
Cargo.lock
generated
|
@ -227,6 +227,23 @@ dependencies = [
|
|||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-graphql-axum"
|
||||
version = "7.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c95b41ba3c0f4ecccd73bf7e7aa7be3c41ff054968e988317bd9133ed210a4a2"
|
||||
dependencies = [
|
||||
"async-graphql",
|
||||
"axum",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"tokio-stream",
|
||||
"tokio-util",
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-graphql-derive"
|
||||
version = "7.0.16"
|
||||
|
@ -392,6 +409,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "021e862c184ae977658b36c4500f7feac3221ca5da43e3f25bd04ab6c79a29b5"
|
||||
dependencies = [
|
||||
"axum-core",
|
||||
"base64",
|
||||
"bytes",
|
||||
"form_urlencoded",
|
||||
"futures-util",
|
||||
|
@ -411,8 +429,10 @@ dependencies = [
|
|||
"serde_json",
|
||||
"serde_path_to_error",
|
||||
"serde_urlencoded",
|
||||
"sha1",
|
||||
"sync_wrapper",
|
||||
"tokio",
|
||||
"tokio-tungstenite",
|
||||
"tower",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
|
@ -761,6 +781,12 @@ dependencies = [
|
|||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "data-encoding"
|
||||
version = "2.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476"
|
||||
|
||||
[[package]]
|
||||
name = "der"
|
||||
version = "0.7.10"
|
||||
|
@ -863,6 +889,8 @@ name = "dpts-server"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"argon2",
|
||||
"async-graphql",
|
||||
"async-graphql-axum",
|
||||
"axum",
|
||||
"chrono",
|
||||
"clap",
|
||||
|
@ -3147,6 +3175,32 @@ dependencies = [
|
|||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-tungstenite"
|
||||
version = "0.26.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a9daff607c6d2bf6c16fd681ccb7eecc83e4e2cdc1ca067ffaadfca5de7f084"
|
||||
dependencies = [
|
||||
"futures-util",
|
||||
"log",
|
||||
"tokio",
|
||||
"tungstenite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-util"
|
||||
version = "0.7.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "66a539a9ad6d5d281510d5bd368c973d636c02dbf8a67300bfb6b950696ad7df"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"futures-sink",
|
||||
"pin-project-lite",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.8.22"
|
||||
|
@ -3263,6 +3317,23 @@ dependencies = [
|
|||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tungstenite"
|
||||
version = "0.26.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4793cb5e56680ecbb1d843515b23b6de9a75eb04b66643e256a396d43be33c13"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"data-encoding",
|
||||
"http",
|
||||
"httparse",
|
||||
"log",
|
||||
"rand 0.9.1",
|
||||
"sha1",
|
||||
"thiserror 2.0.12",
|
||||
"utf-8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.18.0"
|
||||
|
@ -3319,6 +3390,12 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utf-8"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
|
||||
|
||||
[[package]]
|
||||
name = "utf16_iter"
|
||||
version = "1.0.5"
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("Parse int error")]
|
||||
ParseInt(#[from] std::num::ParseIntError),
|
||||
#[error("Missing config value: ({0})")]
|
||||
MissingConfig(String)
|
||||
}
|
|
@ -1,10 +1,8 @@
|
|||
pub mod error;
|
||||
mod reader;
|
||||
mod record;
|
||||
mod table;
|
||||
mod writer;
|
||||
|
||||
use error::Error;
|
||||
pub use reader::CsvReader;
|
||||
pub use record::CsvRecord;
|
||||
pub use table::CsvTable;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
use async_graphql::SimpleObject;
|
||||
use chrono::{DateTime, FixedOffset,};
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, SimpleObject, Deserialize)]
|
||||
#[sea_orm(table_name = "user")]
|
||||
#[graphql(concrete(name = "User", params()))]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
#[serde(skip_deserializing)]
|
||||
|
@ -15,22 +17,6 @@ pub struct Model {
|
|||
pub updated_at: DateTimeWithTimeZone,
|
||||
}
|
||||
|
||||
#[async_graphql::Object]
|
||||
impl Model {
|
||||
pub async fn id(&self) -> i32 {
|
||||
self.id
|
||||
}
|
||||
pub async fn login_name(&self) -> String {
|
||||
self.login_name.clone()
|
||||
}
|
||||
pub async fn created_at(&self) -> DateTimeWithTimeZone {
|
||||
self.created_at.clone()
|
||||
}
|
||||
pub async fn updated_at(&self) -> DateTimeWithTimeZone {
|
||||
self.updated_at.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, DeriveRelation, EnumIter)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::record_header::Entity")]
|
||||
|
|
|
@ -3,4 +3,8 @@ mod query;
|
|||
mod record_detail;
|
||||
mod record_header;
|
||||
mod record_tag;
|
||||
mod user;
|
||||
mod user;
|
||||
|
||||
pub use mutation::Mutation;
|
||||
pub use query::Query;
|
||||
pub use user::UserObject;
|
|
@ -0,0 +1,10 @@
|
|||
use async_graphql::*;
|
||||
|
||||
pub struct Mutation;
|
||||
|
||||
#[Object]
|
||||
impl Mutation {
|
||||
async fn login(&self, username:String, password: String) -> Result<String> {
|
||||
todo!()
|
||||
}
|
||||
}
|
|
@ -1,10 +1,18 @@
|
|||
use async_graphql::*;
|
||||
use async_graphql::{
|
||||
*,
|
||||
http::GraphiQLSource,
|
||||
};
|
||||
use axum::{
|
||||
response::{Html, IntoResponse},
|
||||
routing::get,
|
||||
Router,
|
||||
};
|
||||
use super::user::UserObject;
|
||||
struct Query;
|
||||
pub struct Query;
|
||||
|
||||
#[Object]
|
||||
impl Query {
|
||||
async fn user(&self, username: String) -> Result<Option<UserObject>> {
|
||||
pub async fn user(&self, username: String) -> Result<Option<UserObject>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ repository.workspace = true
|
|||
|
||||
[dependencies]
|
||||
argon2 = "0.5.3"
|
||||
async-graphql.workspace = true
|
||||
axum = "0.8.4"
|
||||
clap = {workspace = true, features = ["derive"]}
|
||||
dpts-core = {workspace = true}
|
||||
|
@ -16,3 +17,4 @@ thiserror.workspace = true
|
|||
tokio.workspace = true
|
||||
toml.workspace = true
|
||||
rand = "0.9.1"
|
||||
async-graphql-axum = "7.0.16"
|
||||
|
|
15
dpts-server/src/graphql.rs
Normal file
15
dpts-server/src/graphql.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
use async_graphql::{EmptySubscription, Schema};
|
||||
use async_graphql_axum::GraphQL;
|
||||
use axum::{routing::get, Router};
|
||||
use dpts_core::graphql::{
|
||||
Query,
|
||||
Mutation,
|
||||
};
|
||||
|
||||
pub fn build_schema() -> Schema<Query, Mutation, EmptySubscription>{
|
||||
Schema::build(Query, Mutation, EmptySubscription).finish()
|
||||
}
|
||||
|
||||
pub fn build_service() -> GraphQL<Schema<Query, Mutation, EmptySubscription>> {
|
||||
GraphQL::new(build_schema())
|
||||
}
|
|
@ -2,4 +2,21 @@ mod args;
|
|||
mod auth;
|
||||
mod config;
|
||||
pub mod error;
|
||||
pub use args::Args;
|
||||
pub mod graphql;
|
||||
|
||||
pub use args::Args;
|
||||
use async_graphql::{EmptySubscription, Schema};
|
||||
use async_graphql_axum::{
|
||||
GraphQL,
|
||||
|
||||
};
|
||||
use axum::{routing::get, Router};
|
||||
use crate::graphql::build_service;
|
||||
|
||||
|
||||
|
||||
pub fn build_app() -> Router {
|
||||
let router = Router::new()
|
||||
.route_service("/graphql", build_service());
|
||||
router
|
||||
}
|
|
@ -1,8 +1,21 @@
|
|||
use dpts_server::Args;
|
||||
|
||||
use async_graphql::{http::{playground_source, GraphQLPlaygroundConfig}, *};
|
||||
use async_graphql_axum::GraphQL;
|
||||
use dpts_core::graphql::{
|
||||
Mutation,
|
||||
Query,
|
||||
};
|
||||
use dpts_server::{build_app, Args};
|
||||
use axum::{response::{Html, IntoResponse}, routing::get, Router};
|
||||
use clap::Parser;
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
println!("{:?}", args);
|
||||
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
axum::serve(
|
||||
tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(),
|
||||
crate::build_app()
|
||||
).await.unwrap()
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue