3b7ed74d11
- examples to fix still - error_extensions.md ResultExt example does not compile! - trait ErrorExtensions is not implemented for ParseIntError - dataloader - requires sqlx to work. So we either "stub" it OR we rewrite them simpler to use a simple "faux" db library
1.0 KiB
1.0 KiB
查询和变更
查询根对象
查询根对象是一个GraphQL对象,定义类似其它对象。查询对象的所有字段Resolver函数是并发执行的。
# extern crate async_graphql;
use async_graphql::*;
# #[derive(SimpleObject)]
# struct User { a: i32 }
struct Query;
#[Object]
impl Query {
async fn user(&self, username: String) -> Result<Option<User>> {
// 在数据库中查找用户
# todo!()
}
}
变更根对象
变更根对象也是一个GraphQL,但变更根对象的执行是顺序的,只有第一个变更执行完成之后才会执行下一个。
下面的变更根对象提供用户注册和登录操作:
# extern crate async_graphql;
use async_graphql::*;
struct Mutation;
#[Object]
impl Mutation {
async fn signup(&self, username: String, password: String) -> Result<bool> {
// 用户注册
# todo!()
}
async fn login(&self, username: String, password: String) -> Result<String> {
// 用户登录并生成token
# todo!()
}
}