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

Boxed traits should work in unions. #780

Closed
boardmaster357 opened this issue Jan 10, 2022 · 2 comments
Closed

Boxed traits should work in unions. #780

boardmaster357 opened this issue Jan 10, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@boardmaster357
Copy link
Contributor

Support for graphql trait objects has been added, but it should also work as a member of a Union

The following fails with the error: the trait bound Box<dyn ProductTrait>: async_graphql::ObjectType is not satisfied

pub trait ProductTrait: Send + Sync {
    fn id(&self) -> &str;
}

#[Object]
impl dyn ProductTrait {
    #[graphql(name = "id")]
    async fn gql_id(&self, _ctx: &Context<'_>) -> &str {
        self.id()
    }
}

#[derive(Union)]
pub enum Content {
    Product(Box<dyn ProductTrait>),
}
@boardmaster357 boardmaster357 added the enhancement New feature or request label Jan 10, 2022
@sunli829
Copy link
Collaborator

Thanks for the sponsorship, I'll fixed this tomorrow. 🙂

sunli829 added a commit that referenced this issue Jan 11, 2022
@sunli829
Copy link
Collaborator

Fixed in 3.0.21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants