Merge branch 'master' of github.com:async-graphql/async-graphql
This commit is contained in:
commit
456f776fdb
|
@ -11,6 +11,8 @@ pub fn generate(object_args: &args::MergedObject) -> GeneratorResult<TokenStream
|
|||
let crate_name = get_crate_name(object_args.internal);
|
||||
let ident = &object_args.ident;
|
||||
let extends = object_args.extends;
|
||||
let generics = &object_args.generics;
|
||||
let where_clause = &generics.where_clause;
|
||||
let gql_typename = object_args
|
||||
.name
|
||||
.clone()
|
||||
|
@ -55,7 +57,7 @@ pub fn generate(object_args: &args::MergedObject) -> GeneratorResult<TokenStream
|
|||
|
||||
let expanded = quote! {
|
||||
#[allow(clippy::all, clippy::pedantic)]
|
||||
impl #crate_name::Type for #ident {
|
||||
impl #generics #crate_name::Type for #ident #generics #where_clause {
|
||||
fn type_name() -> ::std::borrow::Cow<'static, ::std::primitive::str> {
|
||||
::std::borrow::Cow::Borrowed(#gql_typename)
|
||||
}
|
||||
|
@ -88,7 +90,7 @@ pub fn generate(object_args: &args::MergedObject) -> GeneratorResult<TokenStream
|
|||
|
||||
#[allow(clippy::all, clippy::pedantic)]
|
||||
#[#crate_name::async_trait::async_trait]
|
||||
impl #crate_name::resolver_utils::ContainerType for #ident {
|
||||
impl #generics #crate_name::resolver_utils::ContainerType for #ident #generics #where_clause {
|
||||
async fn resolve_field(&self, ctx: &#crate_name::Context<'_>) -> #crate_name::ServerResult<::std::option::Option<#crate_name::Value>> {
|
||||
#create_merged_obj.resolve_field(ctx).await
|
||||
}
|
||||
|
@ -100,13 +102,13 @@ pub fn generate(object_args: &args::MergedObject) -> GeneratorResult<TokenStream
|
|||
|
||||
#[allow(clippy::all, clippy::pedantic)]
|
||||
#[#crate_name::async_trait::async_trait]
|
||||
impl #crate_name::OutputValueType for #ident {
|
||||
impl #generics #crate_name::OutputValueType for #ident #generics #where_clause {
|
||||
async fn resolve(&self, ctx: &#crate_name::ContextSelectionSet<'_>, _field: &#crate_name::Positioned<#crate_name::parser::types::Field>) -> #crate_name::ServerResult<#crate_name::Value> {
|
||||
#crate_name::resolver_utils::resolve_container(ctx, self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl #crate_name::ObjectType for #ident {}
|
||||
impl #generics #crate_name::ObjectType for #ident #generics #where_clause {}
|
||||
};
|
||||
Ok(expanded.into())
|
||||
}
|
||||
|
|
|
@ -336,3 +336,54 @@ pub async fn test_issue_316() {
|
|||
let schema = Schema::new(Query, Mutation::default(), EmptySubscription);
|
||||
assert!(schema.execute("{ _service { sdl }}").await.is_ok());
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
pub async fn test_issue_333() {
|
||||
#[derive(SimpleObject)]
|
||||
struct ObjectA<'a> {
|
||||
field_a: &'a str,
|
||||
}
|
||||
|
||||
#[derive(SimpleObject)]
|
||||
struct ObjectB<'a> {
|
||||
field_b: &'a str,
|
||||
}
|
||||
|
||||
#[derive(MergedObject)]
|
||||
pub struct Object<'a>(ObjectA<'a>, ObjectB<'a>);
|
||||
|
||||
struct Query {
|
||||
a: String,
|
||||
b: String,
|
||||
}
|
||||
|
||||
#[Object]
|
||||
impl Query {
|
||||
async fn obj(&self) -> Object<'_> {
|
||||
Object(ObjectA { field_a: &self.a }, ObjectB { field_b: &self.b })
|
||||
}
|
||||
}
|
||||
|
||||
let schema = Schema::new(
|
||||
Query {
|
||||
a: "haha".to_string(),
|
||||
b: "hehe".to_string(),
|
||||
},
|
||||
EmptyMutation,
|
||||
EmptySubscription,
|
||||
);
|
||||
assert_eq!(
|
||||
schema
|
||||
.execute("{ obj { fieldA fieldB } }")
|
||||
.await
|
||||
.into_result()
|
||||
.unwrap()
|
||||
.data,
|
||||
value!({
|
||||
"obj": {
|
||||
"fieldA": "haha",
|
||||
"fieldB": "hehe",
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user