graphql-go / graphql-go/graphql

Bug with underscore and same name in keys from json response

Open
#675 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
10.1k
Forks
845
PR merge metrics
No merged PRs in 30d

Description

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.

```json
{
"_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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.