graphql-go / graphql

An implementation of GraphQL for Go / Golang
MIT License
9.82k stars 836 forks source link

Bug with underscore and same name in keys from json response #675

Open manuelabarca opened 11 months ago

manuelabarca commented 11 months ago

Good afternoon, I am having a problem with a json that comes as a response to an external endpoint. This json brings the following key values.

{
"_type": "product_result",
"type": {
  "_type": "product_type",
  "master": true
 }
}

When I assemble the graphql object, I assemble it as follows.

"_type": &graphql.Field{
                Type: graphql.String,
            },
"type": &graphql.Field{ Type.
                Type: GQLProductType,
            },

var GQLProductType = graphql.NewObject(
    graphql.ObjectConfig{
        Name: "Type",
        Fields: graphql.Fields{
            "_type": &graphql.Field{
                Type: graphql.String,
            },
            "master": &graphql.Field{
                Type: graphql.Boolean,
            },
        },
    })

but when I launch the query to see if everything is working, the first field arrives ok but the second one that brings an object, the values of the keys of the object are null. I made the test eliminating or omitting the first "_type" and then the results are not null in the object of the second field. It is as if it replaced it or got confused when replacing things. Has anyone had something similar happen? or do you know if there is a problem with underscored key names? As if _type is equal to type and that's why this "bug" happens?

Greetings.