Skip to content

graphql_union from tagged union of structs #586

@arlyon

Description

@arlyon

Describe the solution you'd like

It would be cool to be able to define GraphQL unions like so:

#[derive(GraphQLObject)]
struct Square {
    /// length of one side
    pub length: i32,
}

#[derive(GraphQLObject)]
struct Circle {
    /// radius of the circle
    pub radius: i32,
}

#[juniper::graphql_union]
enum Shape {
    Square(Square),
    Circle(Circle),
}

I understand the current implementation is quite similar already, however it would be cool if we could pull the boilerplate into the macro somehouw..

Describe alternatives you've considered

This would be an alternative (and more ergonomic) alternative to the current implementation. Here is it in use (imagine a query that returns a FieldResult<Shape>):

query {
    getShapes {
        ...on Square { length }
        ...on Circle { radius }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovement of existing features or bugfix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions