diff --git a/codegen/type.go b/codegen/type.go index 9b3b799ae5c..276b4130847 100644 --- a/codegen/type.go +++ b/codegen/type.go @@ -105,7 +105,10 @@ func (t Type) unmarshal(result, raw string, remainingMods []string, depth int) s var rawIf = "rawIf" + strconv.Itoa(depth) var index = "idx" + strconv.Itoa(depth) - return tpl(`{{.rawSlice}} := {{.raw}}.([]interface{}) + return tpl(`var {{.rawSlice}} []interface{} + if {{.raw}} != nil { + {{.rawSlice}} = {{.raw}}.([]interface{}) + } {{.result}} = make({{.type}}, len({{.rawSlice}})) for {{.index}} := range {{.rawSlice}} { {{ .next -}} diff --git a/example/dataloader/generated.go b/example/dataloader/generated.go index 0b0b4d87e71..69cb4b6e695 100644 --- a/example/dataloader/generated.go +++ b/example/dataloader/generated.go @@ -459,10 +459,16 @@ func (ec *executionContext) _Query_torture(ctx context.Context, field graphql.Co var arg0 [][]int if tmp, ok := field.Args["customerIds"]; ok { var err error - rawIf1 := tmp.([]interface{}) + var rawIf1 []interface{} + if tmp != nil { + rawIf1 = tmp.([]interface{}) + } arg0 = make([][]int, len(rawIf1)) for idx1 := range rawIf1 { - rawIf2 := rawIf1[idx1].([]interface{}) + var rawIf2 []interface{} + if rawIf1[idx1] != nil { + rawIf2 = rawIf1[idx1].([]interface{}) + } arg0[idx1] = make([]int, len(rawIf2)) for idx2 := range rawIf2 { arg0[idx1][idx2], err = graphql.UnmarshalInt(rawIf2[idx2])