This commit is contained in:
parent
1d0e96ead4
commit
fb3706ff38
26
src/app.rs
26
src/app.rs
@ -94,19 +94,19 @@ pub async fn create_router(
|
||||
Router::new()
|
||||
.route("/", get(graphql_playground))
|
||||
.route("/graphql", get(graphql_playground).post(graphql_handler))
|
||||
// .route_layer(
|
||||
// RateLimitLayer::<RealIp>::builder()
|
||||
// .with_route(
|
||||
// (Method::GET, "/graphql"),
|
||||
// Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()),
|
||||
// )
|
||||
// .with_route(
|
||||
// (Method::POST, "/graphql"),
|
||||
// Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()),
|
||||
// )
|
||||
// .with_gc_interval(1000)
|
||||
// .default_handle_error(),
|
||||
// )
|
||||
.route_layer(
|
||||
RateLimitLayer::<RealIp>::builder()
|
||||
.with_route(
|
||||
(Method::GET, "/graphql"),
|
||||
Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()),
|
||||
)
|
||||
.with_route(
|
||||
(Method::POST, "/graphql"),
|
||||
Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()),
|
||||
)
|
||||
.with_gc_interval(1000)
|
||||
.default_handle_error(),
|
||||
)
|
||||
.route_service("/ws", GraphQLSubscription::new(schema))
|
||||
.layer(CorsLayer::permissive())
|
||||
.merge(router)
|
||||
|
||||
@ -1246,8 +1246,6 @@ impl QueryRoot {
|
||||
|
||||
// ==================== Blog 相关查询 ====================
|
||||
|
||||
/// 获取博客文章列表
|
||||
#[graphql(guard = "RequireReadPermission::new(\"blogs\")")]
|
||||
async fn blogs(
|
||||
&self,
|
||||
ctx: &Context<'_>,
|
||||
@ -1263,7 +1261,6 @@ impl QueryRoot {
|
||||
}
|
||||
|
||||
/// 根据ID获取博客文章
|
||||
#[graphql(guard = "RequireReadPermission::new(\"blogs\")")]
|
||||
async fn blog(&self, ctx: &Context<'_>, id: Uuid) -> Result<Blog> {
|
||||
let blog_service = ctx.data::<BlogService>()?;
|
||||
blog_service
|
||||
@ -1273,7 +1270,6 @@ impl QueryRoot {
|
||||
}
|
||||
|
||||
/// 根据slug获取博客文章
|
||||
#[graphql(guard = "RequireReadPermission::new(\"blogs\")")]
|
||||
async fn blog_by_slug(&self, ctx: &Context<'_>, slug: String) -> Result<Blog> {
|
||||
let blog_service = ctx.data::<BlogService>()?;
|
||||
blog_service
|
||||
@ -1282,8 +1278,6 @@ impl QueryRoot {
|
||||
.map_err(|e| GraphQLError::new(e.to_string()))
|
||||
}
|
||||
|
||||
/// 获取博客文章详情(包含分类和标签)
|
||||
#[graphql(guard = "RequireReadPermission::new(\"blogs\")")]
|
||||
async fn blog_detail(&self, ctx: &Context<'_>, id: Uuid) -> Result<BlogDetail> {
|
||||
let blog_service = ctx.data::<BlogService>()?;
|
||||
blog_service
|
||||
@ -1292,8 +1286,6 @@ impl QueryRoot {
|
||||
.map_err(|e| GraphQLError::new(e.to_string()))
|
||||
}
|
||||
|
||||
/// 获取博客统计信息
|
||||
#[graphql(guard = "RequireReadPermission::new(\"blogs\")")]
|
||||
async fn blog_stats(&self, ctx: &Context<'_>) -> Result<BlogStats> {
|
||||
let blog_service = ctx.data::<BlogService>()?;
|
||||
blog_service
|
||||
@ -1302,8 +1294,6 @@ impl QueryRoot {
|
||||
.map_err(|e| GraphQLError::new(e.to_string()))
|
||||
}
|
||||
|
||||
/// 获取博客分类列表
|
||||
#[graphql(guard = "RequireReadPermission::new(\"blog_categories\")")]
|
||||
async fn blog_categories(
|
||||
&self,
|
||||
ctx: &Context<'_>,
|
||||
@ -1316,8 +1306,6 @@ impl QueryRoot {
|
||||
.map_err(|e| GraphQLError::new(e.to_string()))
|
||||
}
|
||||
|
||||
/// 根据ID获取博客分类
|
||||
#[graphql(guard = "RequireReadPermission::new(\"blog_categories\")")]
|
||||
async fn blog_category(&self, ctx: &Context<'_>, id: Uuid) -> Result<BlogCategory> {
|
||||
let blog_service = ctx.data::<BlogService>()?;
|
||||
blog_service
|
||||
@ -1326,8 +1314,6 @@ impl QueryRoot {
|
||||
.map_err(|e| GraphQLError::new(e.to_string()))
|
||||
}
|
||||
|
||||
/// 获取博客标签列表
|
||||
#[graphql(guard = "RequireReadPermission::new(\"blog_tags\")")]
|
||||
async fn blog_tags(
|
||||
&self,
|
||||
ctx: &Context<'_>,
|
||||
@ -1340,8 +1326,6 @@ impl QueryRoot {
|
||||
.map_err(|e| GraphQLError::new(e.to_string()))
|
||||
}
|
||||
|
||||
/// 根据ID获取博客标签
|
||||
#[graphql(guard = "RequireReadPermission::new(\"blog_tags\")")]
|
||||
async fn blog_tag(&self, ctx: &Context<'_>, id: Uuid) -> Result<BlogTag> {
|
||||
let blog_service = ctx.data::<BlogService>()?;
|
||||
blog_service
|
||||
|
||||
Loading…
Reference in New Issue
Block a user