pub use async_graphql::{
ComplexObject, Enum, InputObject, Interface, Object, SimpleObject, Subscription, Union,
};
pub mod field {
pub use async_graphql::ID;
}
pub mod resolver {
pub use async_graphql::{Object, Subscription};
}
pub mod input {
pub use async_graphql::InputObject;
}
pub mod types {
pub use async_graphql::{Enum, Interface, SimpleObject, Union};
}
pub mod context {
pub use async_graphql::Context;
}
#[macro_export]
macro_rules! resolver {
(
$(#[$meta:meta])*
$vis:vis struct $name:ident {
$($field:ident: $field_ty:ty),* $(,)?
}
impl $impl_name:ident {
$(
$(#[$method_meta:meta])*
async fn $method:ident(&self $(, $arg:ident: $arg_ty:ty)*) -> $ret:ty $body:block
)*
}
) => {
$(#[$meta])*
$vis struct $name {
$($field: $field_ty),*
}
#[async_graphql::Object]
impl $impl_name {
$(
$(#[$method_meta])*
async fn $method(&self $(, $arg: $arg_ty)*) -> $ret $body
)*
}
};
}
#[cfg(test)]
mod tests {
use super::*;
use async_graphql::ID;
#[derive(SimpleObject)]
struct TestUser {
id: ID,
name: String,
}
#[test]
fn test_simple_object() {
let user = TestUser {
id: ID::from("1"),
name: "Test".to_string(),
};
assert_eq!(user.name, "Test");
}
}