forked from shurcooL/graphql
-
Notifications
You must be signed in to change notification settings - Fork 99
Open
Description
Having a look at this unit test I think that union types unmarshalling is not well implemented:
I would have expected only the field corresponding to the __typename
to be filled...
In other words I would have expected the following test to pass:
func TestUnmarshalGraphQL_union(t *testing.T) {
/*
{
__typename
... on ClosedEvent {
createdAt
actor {login}
}
... on ReopenedEvent {
createdAt
actor {login}
}
}
*/
type actor struct{ Login string }
type closedEvent struct {
Actor actor
CreatedAt time.Time
}
type reopenedEvent struct {
Actor actor
CreatedAt time.Time
}
type issueTimelineItem struct {
Typename string `graphql:"__typename"`
ClosedEvent closedEvent `graphql:"... on ClosedEvent"`
ReopenedEvent reopenedEvent `graphql:"... on ReopenedEvent"`
}
var got issueTimelineItem
err := jsonutil.UnmarshalGraphQL([]byte(`{
"__typename": "ClosedEvent",
"createdAt": "2017-06-29T04:12:01Z",
"actor": {
"login": "shurcooL-test"
}
}`), &got)
if err != nil {
t.Fatal(err)
}
want := issueTimelineItem{
Typename: "ClosedEvent",
ClosedEvent: closedEvent{
Actor: actor{
Login: "shurcooL-test",
},
CreatedAt: time.Unix(1498709521, 0).UTC(),
},
}
if !reflect.DeepEqual(got, want) {
t.Error("not equal")
}
}
chris-rock
Metadata
Metadata
Assignees
Labels
No labels