12个版本 (6个重大更新)
| 0.8.0 | 2022年6月22日 | 
|---|---|
| 0.7.1 | 2022年6月19日 | 
| 0.6.1 | 2022年6月16日 | 
| 0.5.0 | 2022年6月16日 | 
| 0.1.0 | 2022年6月13日 | 
#98 in #folder
每月40次下载
88KB
 2.5K  SLoC
aqlgen
async-graphql 4.x的模式生成器
快速开始
安装
为了安装,只需运行以下命令
cargo install aqlgen
用法
通过4个简单步骤生成async-graphql 4.x模式
- 创建一个新的空Rust模块
//! main.rs
mod schema;
...
- 将您的模式放在任何文件夹中
# example schema
type Book {
    id: ID!
    name: String!
    author: String!
}
input InputBook {
    name: String!
    author: String!
}
type QueryRoot {
    books: [Book!]
}
type MutationRoot {
    createBook(book: InputBook!): Book
}
- 运行aqlgen
# in project/src
cargo aqlgen --schema schema.graphql --output schema
- 享受您的生成过程
//! book.rs
use async_graphql::*;
#[derive(Debug)]
pub struct Book;
#[Object]
impl Book {
    pub async fn id(&self, ctx: &Context<'_>) -> ID {
        todo!()
    }
    
    pub async fn name(&self, ctx: &Context<'_>) -> String {
        todo!()
    }
    
    pub async fn author(&self, ctx: &Context<'_>) -> String {
        todo!()
    }
}
//! input_book.rs
use async_graphql::*;
#[derive(InputObject, Debug)]
pub struct InputBook {
    pub name: String,
    pub author: String,
}
//! query_root.rs
use super::super::Book;
use async_graphql::*;
#[derive(Debug)]
pub struct QueryRoot;
#[Object]
impl QueryRoot {
    pub async fn books(&self, ctx: &Context<'_>) -> Option<Vec<Book>> {
        todo!()
    }
}
//! mutation_root.rs
use super::super::{Book, InputBook};
use async_graphql::*;
#[derive(Debug)]
pub struct MutationRoot;
#[Object]
impl MutationRoot {
    pub async fn create_book(&self, ctx: &Context<'_>, book: InputBook) -> Option<Book> {
        todo!()
    }
}
依赖关系
~16–28MB
~493K SLoC