getoutreach / goql

A GraphQL client package written in Go.
Apache License 2.0
19 stars 2 forks source link

Sparse fieldset name collision #49

Closed grevych closed 2 years ago

grevych commented 2 years ago

MarshalQuery and most probably MarshalMutation show a strange behaviour when the following scenario happens:

Here an example:

{
    Name: "Test",
    Input: struct {
        TestQuery struct {
            FieldOne    string
            FieldTwo    string
            FieldThree  string
            NestedField struct {
                FieldOne string
                FieldTwo string
                FieldXYZ string
                FieldABC string `goql:"keep"`
            } `goql:"keep"`
        } `goql:"testQuery(id:$id<ID!>)"`
    }{},
    Fields: Fields{
        "fieldOne": true,
        "fieldTwo": true,
        "nestedField": Fields{
            "fieldXYZ": true,
        },
    },
    ExpectedOutput: `query($id: ID!) {
testQuery(id: $id) {
fieldOne
fieldTwo
nestedField {
fieldXYZ
}
}
}`,
    },
},

At first glance, seems that the parsing process of the children shares the same map level of the fields object as the parent

Expected output:

query($id: ID!) {
testQuery(id: $id) {
fieldOne
fieldTwo
nestedField {
fieldXYZ
}
}
}

Actual output:

query($id: ID!) {
testQuery(id: $id) {
fieldOne
fieldTwo
nestedField {
fieldOne
fieldTwo
fieldABC
}
}
}

Branch with broken test: https://github.com/getoutreach/goql/tree/grevych/issue/sparse-fieldset-name-collision