aPureBase / KGraphQL

Pure Kotlin GraphQL implementation
https://kgraphql.io
MIT License
298 stars 58 forks source link

When using fragments, executor resolves a property that is not going to be returned #197

Closed thevietto closed 1 year ago

thevietto commented 1 year ago

given the following schema:

query("outer") {
    resolver { ->
        Outer(Inner("test"))
    }
}
type<Inner> {
    property("testProperty") {
        resolver { "this should be resolved" }
    }
    property("unwantedProperty") {
        resolver {
            "This code should not be executed as it could be an expensive calculation" // <--- here
        }
    }
}

and the following query:

{
    outer {
        ...TestFragment
        inner { testProperty } # override what declared in TestFragment, return only `testProperty`
    }
}
fragment TestFragment on Outer {
    inner { name, testProperty, unwantedProperty }
}

we got the following result, which is fine (or is it?):

{"data":{"outer":{"inner":{"testProperty":"this should be resolved"}}}}

The issue is, the unwantedProperty resolver is still getting executed because that field is declared in TestFragment. Expected behavior is that this resolver is ignored because it is not requested by caller

thevietto commented 1 year ago

Actually, I realized the correct behavior is not what I described. Seems like a GQL engine should merge fragment and properties in that case, and return everything in the response.

{
        "name" : "test",
        "testProperty" : "this should be resolved",
        "unwantedProperty" : "This code should not be executed as it could be an expensive calculation"
}

Still an issue in KGraphQL though..