8000 Flatten in Complex Objects causes resolver with unrequested fields to be called · Issue #1690 · async-graphql/async-graphql · GitHub
[go: up one dir, main page]

Skip to content
Flatten in Complex Objects causes resolver with unrequested fields to be called #1690
@Karechta

Description

@Karechta

Having multiple Resolver for a Complex Object and one of them having a flatten Attribute causes Unexpected Behaviour:

Expected Behaviour

Implementing Resolver A with [graphql(flatten)] and Resolver B without and then Requesting a Field from Resolver B should only call Resolver B.

Actual Behavior

Before it calls Resolver B it calls Resolver A, although it does not need a field from it. Only happens if the flattened Resolver comes first in the ComplexObject implementation.

Reproduction

Here is some test code, which shows the problem
The first test implements the flattened Resolved first, while the second test implements it second.

// will fail
#[tokio::test]
async fn test_1() {
    #[derive(SimpleObject)]
    #[graphql(complex)]
    struct Outer {
        b: i32,
    }

    #[derive(SimpleObject)]
    struct Inner {
        my_int: i32,
    }

    #[ComplexObject]
    impl Outer {
        #[graphql(flatten)]
        async fn a(&self) -> &Inner {
            unreachable!("We called the resolver a")
        }

        async fn c(&self) -> i32 {
            println!("Calling resolver c");
            42
        }
    }

    let schema = Schema::new(Outer {b: 10}, EmptyMutation, EmptySubscription);
    let query = "{ c }";
    schema.execute(query).await; 
}

// will not fail
#[tokio::test]
async fn test_2() {
    #[derive(SimpleObject)]
    #[graphql(complex)]
    struct Outer {
        b: i32,
    }

    #[derive(SimpleObject)]
    struct Inner {
        my_int: i32,
    }

    #[ComplexObject]
    impl Outer {
        async fn c(&self) -> i32 {
            println!("Calling resolver c");
            42
        }

        #[graphql(flatten)]
        async fn a(&self) -> &Inner {
            unreachable!("We called the resolver a")
        }
    }

    let schema = Schema::new(Outer {b: 10}, EmptyMutation, EmptySubscription);
    let query = "{ c }";
    schema.execute(query).await; 
}

Specification

  • Version: 7.0.15

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0