From 682980790f99c114933665b263cf685e37627326 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Tue, 6 Jul 2021 16:03:23 +0900 Subject: [PATCH] fixed logic --- graphql.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/graphql.go b/graphql.go index 0804036..f402029 100644 --- a/graphql.go +++ b/graphql.go @@ -343,21 +343,19 @@ func fixStructWithTypename(v reflect.Value) { // If the field is a fragment and does not match the typename, // initialize the struct for i := 0; i < v.NumField(); i++ { - // case of "foo": [...] - if v.Field(i).Kind() == reflect.Slice { - fixStructWithTypename(v.Field(i)) - continue - } - - if typeName == "" { - return - } - // case of field is like "fragmentField fragmentField `graphql:"... on Fragment"`" fieldType := v.Type().Field(i) if isGraphQLFragment(fieldType) && notEqualToTypeCondition(fieldType, typeName) { e := v.Field(i) v.Field(i).Set(reflect.Zero(e.Type())) + } else { + // Fields that are not initialized are further explored. + switch v.Field(i).Kind() { + case reflect.Ptr, + reflect.Slice, // case of "foo": [...] + reflect.Struct: // case of "foo": {...} + fixStructWithTypename(v.Field(i)) + } } } }