Skip to content

Commit

Permalink
Merge pull request #3 from Code-Hex/fix/retrive
Browse files Browse the repository at this point in the history
Fix retrive
  • Loading branch information
Code-Hex authored Jul 6, 2021
2 parents 00adb7e + 6829807 commit b1103d0
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
}
Expand Down

0 comments on commit b1103d0

Please sign in to comment.