Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Flatten fields with user-defined resolvers #1752

@JakeNeau

Description

@JakeNeau

Description of the feature

It would be nice to be able to use #[graphql(flatten)] with the fields with user-defined resolvers in complex objects. This would be useful for when two or more pieces of data are fetched by a resolver, and it is difficult to separate them (e.g. two values fetched from one row of a database in a single access).

Code example

#[derive(SimpleObject)]
pub struct ChildObject {
    b: String,
    c: String,
}

#[derive(SimpleObject)]
#[graphql(complex)]
pub struct ParentObject {
    a: String,
}

#[ComplexObject]
impl ParentObject {
    #[graphql(flatten)]
    async fn child(&self, ctx: &Context<'_>) -> Result<ChildObject> {
        // Some code that fetches data for and constructs the child object based on the 'a' field
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions