Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack overflow at Schema::new() when generic type's method returns self #1451

Open
JacobZwang opened this issue Dec 28, 2023 · 0 comments
Open
Labels
bug Something isn't working

Comments

@JacobZwang
Copy link

Expected Behavior

A generic impl should be able to return a type of the same type as itself.

Actual Behavior

When calling Schema::new(), the schema will enter a recursive loop calling async_graphql::OutputType>::create_type_info(registry) until it crashes.

Steps to Reproduce the Problem

use async_graphql::{
    ComplexObject, ContainerType, EmptyMutation, EmptySubscription, Object, OutputType, Schema,
    SimpleObject,
};
use std::marker::PhantomData;

#[derive(SimpleObject)]
#[graphql(concrete(name = "SpecificObject", params(SpecificObject)))]
#[graphql(complex)]
pub struct GenericObject<T>
where
    T: OutputType + ContainerType,
{
    placeholder: String,
    #[graphql(skip)]
    marker: PhantomData<T>,
}

#[ComplexObject]
impl<T> GenericObject<T>
where
    T: OutputType + ContainerType,
    GenericObject<T>: OutputType,
{
    // this method causes the stack overflow
    async fn test(&self) -> GenericObject<T> {
        unimplemented!()
    }
}

#[derive(SimpleObject)]
struct SpecificObject {
    test: String,
}

#[Object]
impl Query {
    async fn test(&self) -> GenericObject<SpecificObject> {
        unimplemented!()
    }
}

struct Query;

#[test]
fn main() {
    let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
}

Specifications

  • Version: 6.0.11
  • Platform: OSX
@JacobZwang JacobZwang added the bug Something isn't working label Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant