Fix the problem that Description
derived macro do not support generic objects.
This commit is contained in:
parent
096ce92929
commit
194a2ff100
|
@ -7,9 +7,10 @@ pub fn generate(desc_args: &args::Description) -> GeneratorResult<TokenStream> {
|
|||
let crate_name = get_crate_name(desc_args.internal);
|
||||
let ident = &desc_args.ident;
|
||||
let generics = &desc_args.generics;
|
||||
let where_clause = &generics.where_clause;
|
||||
let doc = get_rustdoc(&desc_args.attrs)?.unwrap_or_default();
|
||||
let expanded = quote! {
|
||||
impl #crate_name::Description for #ident #generics {
|
||||
impl #generics #crate_name::Description for #ident #generics #where_clause {
|
||||
fn description() -> &'static str {
|
||||
#doc
|
||||
}
|
||||
|
|
|
@ -32,6 +32,40 @@ pub async fn test_object() {
|
|||
);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
pub async fn test_object_with_lifetime() {
|
||||
/// Haha
|
||||
#[derive(Description, Default)]
|
||||
struct MyObj<'a>(&'a str);
|
||||
|
||||
#[Object(use_type_description)]
|
||||
impl<'a> MyObj<'a> {
|
||||
async fn value(&self) -> &str {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
struct Query;
|
||||
|
||||
#[Object]
|
||||
impl Query {
|
||||
async fn obj(&self) -> MyObj<'_> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||
assert_eq!(
|
||||
schema
|
||||
.execute(r#"{ __type(name: "MyObj") { description } }"#)
|
||||
.await
|
||||
.data,
|
||||
value!({
|
||||
"__type": { "description": "Haha" }
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
pub async fn test_scalar() {
|
||||
/// Haha
|
||||
|
|
Loading…
Reference in New Issue
Block a user