When i start server with go run example/starwars/server/server.go and execute this query :
query TestMerge {
hero {
__typename
name
... on Character {
...Droid
name
__typename
}
}
}
fragment Droid on Droid {
name
__typename
}
GraphiQL merge __typename field but the server response has multiple __typename.
Result with server response (browser network inspect) :
{"data":{"hero":{"__typename":"Droid","name":"R2-D2","__typename":"Droid","__typename":"Droid"}}}
Expected :
{"data":{"hero":{"name":"R2-D2","__typename":"Droid"}}}
With graphql-js __typename is merged.
link #365
Hi, I just ran the following test:
go run example/starwars/server/server.goquery TestMerge {
hero {
__typename
name
... on Character {
...Droid
name
__typename
}
}
}
fragment Droid on Droid {
name
__typename
}

I am closing this issue because I am unable to reproduce it in the latest version of the library.
Oh, I just read more carefully. Indeed, the GraphiQL UI is merging this and is hiding the real problem. I am reopening the issue.

Apparently there is an issue with our unit tests too. I just wrote this unit test and it passes:
func TestMergeTypename(t *testing.T) {
gqltesting.RunTests(t, []*gqltesting.Test{
{
Schema: starwarsSchema,
Query: `
query TestMerge {
hero {
__typename
name
... on Character {
...Droid
name
__typename
}
}
}
fragment Droid on Droid {
name
__typename
}
`,
ExpectedResult: `
{
"hero": {
"name": "R2-D2",
"__typename": "Droid"
}
}
`,
},
})
}
In our testing.go file we have this function:
func formatJSON(data []byte) ([]byte, error) {
var v interface{}
if err := json.Unmarshal(data, &v); err != nil {
return nil, err
}
formatted, err := json.Marshal(v)
if err != nil {
return nil, err
}
return formatted, nil
}
This function hides the real issue during tests 馃う
Oh! yes json.Unmarshal merge same keys 馃
Any idea to fix that? I'll investigate.
@qneyrat any luck with this?
I dont know why field is merged but typename no.
Typename and name has different level in execFieldSelection but field name merged.
Before execFieldSelection
```&{{Character map[appearsIn:0xc000150a80 friends:0xc000150240 friendsConnection:0xc000150300 id:0xc0001500c0 name:0xc000150180] map[Droid:0xc00015e760 Human:0xc00015e020]} __typename}
&{{{name [] String! [] The name of the character} Character 4 [] false false
&{{Character map[appearsIn:0xc000150a80 friends:0xc000150240 friendsConnection:0xc000150300 id:0xc0001500c0 name:0xc000150180] map[Droid:0xc00015e760 Human:0xc00015e020]} __typename}
&{{5 0xc00015eb60} [0xc0001063c0 0xc0001b6090]}
&{{{name [] String! [] What others call this droid} Droid 4 [] false false
&{{Droid map[appearsIn:0xc000151c80 friends:0xc000151800 friendsConnection:0xc0001518c0 id:0xc000151680 name:0xc000151740 primaryFunction:0xc000151d40] map[]} __typename}
After exec (alias of field
0 __typename
1 name
2 __typename
3 __typename
0 hero
```
I haven't had the time to investigate but __typename is supposed to be also a key in the map. Could it be stored with different keys?
Hi,
I just proposed a fix, all tests seems to be still OK and I added a new test to ensure this issue is fixed :-)
Please let me know if you see something I should change because I don't know the code of this library.