From 84b066170081d0c2d16d06ec89e39323062e5d0e Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Mon, 19 Mar 2018 12:34:29 +1100 Subject: [PATCH 1/2] Allow nulls in input fields --- codegen/type.go | 13 +++++--- example/chat/generated.go | 8 ----- example/dataloader/generated.go | 4 --- example/scalars/generated.go | 19 ++++++------ example/starwars/generated.go | 55 ++++++++++++++------------------- example/todo/generated.go | 14 +++------ example/todo/todo_test.go | 9 ++++++ main.go | 1 - test/generated.go | 32 +++++++++---------- 9 files changed, 70 insertions(+), 85 deletions(-) diff --git a/codegen/type.go b/codegen/type.go index 36adb6b4233..87587a4ec50 100644 --- a/codegen/type.go +++ b/codegen/type.go @@ -87,11 +87,14 @@ func (t Type) unmarshal(result, raw string, remainingMods []string, depth int) s case len(remainingMods) > 0 && remainingMods[0] == modPtr: ptr := "ptr" + strconv.Itoa(depth) return tpl(`var {{.ptr}} {{.mods}}{{.t.FullName}} - {{.next}} - {{.result}} = &{{.ptr -}} + if {{.raw}} != nil { + {{.next}} + {{.result}} = &{{.ptr -}} + } `, map[string]interface{}{ "ptr": ptr, "t": t, + "raw": raw, "result": result, "mods": strings.Join(remainingMods[1:], ""), "next": t.unmarshal(ptr, raw, remainingMods[1:], depth+1), @@ -122,11 +125,11 @@ func (t Type) unmarshal(result, raw string, remainingMods []string, depth int) s return tpl(`{{- if .t.CastType }} var castTmp {{.t.FullName}} - {{- end }} + {{ end }} {{- if .t.Marshaler }} - {{ .result }}, err = {{ .t.Marshaler.PkgDot }}Unmarshal{{.t.Marshaler.GoType}}({{.raw}}) + {{- .result }}, err = {{ .t.Marshaler.PkgDot }}Unmarshal{{.t.Marshaler.GoType}}({{.raw}}) {{- else }} - err = (&{{.result}}).UnmarshalGQL({{.raw}}) + err = (&{{.result}}).UnmarshalGQL({{.raw}}) {{- end }} {{- if .t.CastType }} {{ .realResult }} = {{.t.CastType}}(castTmp) diff --git a/example/chat/generated.go b/example/chat/generated.go index 6008f708f2f..ca2e85d677a 100644 --- a/example/chat/generated.go +++ b/example/chat/generated.go @@ -206,7 +206,6 @@ func (ec *executionContext) _Mutation_post(field graphql.CollectedField) graphql var arg0 string if tmp, ok := field.Args["text"]; ok { var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -216,7 +215,6 @@ func (ec *executionContext) _Mutation_post(field graphql.CollectedField) graphql var arg1 string if tmp, ok := field.Args["username"]; ok { var err error - arg1, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -226,7 +224,6 @@ func (ec *executionContext) _Mutation_post(field graphql.CollectedField) graphql var arg2 string if tmp, ok := field.Args["roomName"]; ok { var err error - arg2, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -271,7 +268,6 @@ func (ec *executionContext) _Query_room(field graphql.CollectedField) graphql.Ma var arg0 string if tmp, ok := field.Args["name"]; ok { var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -310,7 +306,6 @@ func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql. var arg0 string if tmp, ok := field.Args["name"]; ok { var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -347,7 +342,6 @@ func (ec *executionContext) _Subscription_messageAdded(field graphql.CollectedFi var arg0 string if tmp, ok := field.Args["roomName"]; ok { var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -770,7 +764,6 @@ func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *in var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error - arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { ec.Error(err) @@ -822,7 +815,6 @@ func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error - arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { ec.Error(err) diff --git a/example/dataloader/generated.go b/example/dataloader/generated.go index 8b4659711b7..0c9cbf6bc8e 100644 --- a/example/dataloader/generated.go +++ b/example/dataloader/generated.go @@ -339,7 +339,6 @@ func (ec *executionContext) _Query_torture(field graphql.CollectedField) graphql rawIf2 := rawIf1[idx1].([]interface{}) arg0[idx1] = make([]int, len(rawIf2)) for idx2 := range rawIf2 { - arg0[idx1][idx2], err = graphql.UnmarshalInt(rawIf2[idx2]) } } @@ -387,7 +386,6 @@ func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql. var arg0 string if tmp, ok := field.Args["name"]; ok { var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -801,7 +799,6 @@ func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *in var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error - arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { ec.Error(err) @@ -853,7 +850,6 @@ func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error - arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { ec.Error(err) diff --git a/example/scalars/generated.go b/example/scalars/generated.go index 78c75b25e75..703a27babdd 100644 --- a/example/scalars/generated.go +++ b/example/scalars/generated.go @@ -94,7 +94,6 @@ func (ec *executionContext) _Query_user(field graphql.CollectedField) graphql.Ma var arg0 string if tmp, ok := field.Args["id"]; ok { var err error - arg0, err = graphql.UnmarshalID(tmp) if err != nil { ec.Error(err) @@ -125,7 +124,6 @@ func (ec *executionContext) _Query_search(field graphql.CollectedField) graphql. var arg0 SearchArgs if tmp, ok := field.Args["input"]; ok { var err error - arg0, err = UnmarshalSearchArgs(tmp) if err != nil { ec.Error(err) @@ -134,7 +132,6 @@ func (ec *executionContext) _Query_search(field graphql.CollectedField) graphql. } else { var tmp interface{} = map[string]interface{}{"location": "37,144"} var err error - arg0, err = UnmarshalSearchArgs(tmp) if err != nil { ec.Error(err) @@ -175,7 +172,6 @@ func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql. var arg0 string if tmp, ok := field.Args["name"]; ok { var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -644,7 +640,6 @@ func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *in var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error - arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { ec.Error(err) @@ -696,7 +691,6 @@ func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error - arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { ec.Error(err) @@ -746,18 +740,23 @@ func UnmarshalSearchArgs(v interface{}) (SearchArgs, error) { case "location": var err error var ptr1 Point + if v != nil { + + err = (&ptr1).UnmarshalGQL(v) + it.Location = &ptr1 + } - err = (&ptr1).UnmarshalGQL(v) - it.Location = &ptr1 if err != nil { return it, err } case "createdAfter": var err error var ptr1 time.Time + if v != nil { + ptr1, err = UnmarshalTimestamp(v) + it.CreatedAfter = &ptr1 + } - ptr1, err = UnmarshalTimestamp(v) - it.CreatedAfter = &ptr1 if err != nil { return it, err } diff --git a/example/starwars/generated.go b/example/starwars/generated.go index 4e3d389ea2f..36d23172083 100644 --- a/example/starwars/generated.go +++ b/example/starwars/generated.go @@ -158,9 +158,11 @@ func (ec *executionContext) _Droid_friendsConnection(field graphql.CollectedFiel if tmp, ok := field.Args["first"]; ok { var err error var ptr1 int + if tmp != nil { + ptr1, err = graphql.UnmarshalInt(tmp) + arg0 = &ptr1 + } - ptr1, err = graphql.UnmarshalInt(tmp) - arg0 = &ptr1 if err != nil { ec.Error(err) return graphql.Null @@ -170,9 +172,11 @@ func (ec *executionContext) _Droid_friendsConnection(field graphql.CollectedFiel if tmp, ok := field.Args["after"]; ok { var err error var ptr1 string + if tmp != nil { + ptr1, err = graphql.UnmarshalID(tmp) + arg1 = &ptr1 + } - ptr1, err = graphql.UnmarshalID(tmp) - arg1 = &ptr1 if err != nil { ec.Error(err) return graphql.Null @@ -375,7 +379,6 @@ func (ec *executionContext) _Human_height(field graphql.CollectedField, obj *Hum var arg0 string if tmp, ok := field.Args["unit"]; ok { var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -384,7 +387,6 @@ func (ec *executionContext) _Human_height(field graphql.CollectedField, obj *Hum } else { var tmp interface{} = "METER" var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -428,9 +430,11 @@ func (ec *executionContext) _Human_friendsConnection(field graphql.CollectedFiel if tmp, ok := field.Args["first"]; ok { var err error var ptr1 int + if tmp != nil { + ptr1, err = graphql.UnmarshalInt(tmp) + arg0 = &ptr1 + } - ptr1, err = graphql.UnmarshalInt(tmp) - arg0 = &ptr1 if err != nil { ec.Error(err) return graphql.Null @@ -440,9 +444,11 @@ func (ec *executionContext) _Human_friendsConnection(field graphql.CollectedFiel if tmp, ok := field.Args["after"]; ok { var err error var ptr1 string + if tmp != nil { + ptr1, err = graphql.UnmarshalID(tmp) + arg1 = &ptr1 + } - ptr1, err = graphql.UnmarshalID(tmp) - arg1 = &ptr1 if err != nil { ec.Error(err) return graphql.Null @@ -522,7 +528,6 @@ func (ec *executionContext) _Mutation_createReview(field graphql.CollectedField) var arg0 string if tmp, ok := field.Args["episode"]; ok { var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -532,7 +537,6 @@ func (ec *executionContext) _Mutation_createReview(field graphql.CollectedField) var arg1 Review if tmp, ok := field.Args["review"]; ok { var err error - arg1, err = UnmarshalReviewInput(tmp) if err != nil { ec.Error(err) @@ -633,7 +637,6 @@ func (ec *executionContext) _Query_hero(field graphql.CollectedField) graphql.Ma var arg0 string if tmp, ok := field.Args["episode"]; ok { var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -642,7 +645,6 @@ func (ec *executionContext) _Query_hero(field graphql.CollectedField) graphql.Ma } else { var tmp interface{} = "NEWHOPE" var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -671,7 +673,6 @@ func (ec *executionContext) _Query_reviews(field graphql.CollectedField) graphql var arg0 string if tmp, ok := field.Args["episode"]; ok { var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -682,9 +683,11 @@ func (ec *executionContext) _Query_reviews(field graphql.CollectedField) graphql if tmp, ok := field.Args["since"]; ok { var err error var ptr1 time.Time + if tmp != nil { + ptr1, err = graphql.UnmarshalTime(tmp) + arg1 = &ptr1 + } - ptr1, err = graphql.UnmarshalTime(tmp) - arg1 = &ptr1 if err != nil { ec.Error(err) return graphql.Null @@ -715,7 +718,6 @@ func (ec *executionContext) _Query_search(field graphql.CollectedField) graphql. var arg0 string if tmp, ok := field.Args["text"]; ok { var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -747,7 +749,6 @@ func (ec *executionContext) _Query_character(field graphql.CollectedField) graph var arg0 string if tmp, ok := field.Args["id"]; ok { var err error - arg0, err = graphql.UnmarshalID(tmp) if err != nil { ec.Error(err) @@ -775,7 +776,6 @@ func (ec *executionContext) _Query_droid(field graphql.CollectedField) graphql.M var arg0 string if tmp, ok := field.Args["id"]; ok { var err error - arg0, err = graphql.UnmarshalID(tmp) if err != nil { ec.Error(err) @@ -806,7 +806,6 @@ func (ec *executionContext) _Query_human(field graphql.CollectedField) graphql.M var arg0 string if tmp, ok := field.Args["id"]; ok { var err error - arg0, err = graphql.UnmarshalID(tmp) if err != nil { ec.Error(err) @@ -837,7 +836,6 @@ func (ec *executionContext) _Query_starship(field graphql.CollectedField) graphq var arg0 string if tmp, ok := field.Args["id"]; ok { var err error - arg0, err = graphql.UnmarshalID(tmp) if err != nil { ec.Error(err) @@ -876,7 +874,6 @@ func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql. var arg0 string if tmp, ok := field.Args["name"]; ok { var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -976,7 +973,6 @@ func (ec *executionContext) _Starship_length(field graphql.CollectedField, obj * var arg0 string if tmp, ok := field.Args["unit"]; ok { var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -985,7 +981,6 @@ func (ec *executionContext) _Starship_length(field graphql.CollectedField, obj * } else { var tmp interface{} = "METER" var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -1412,7 +1407,6 @@ func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *in var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error - arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { ec.Error(err) @@ -1464,7 +1458,6 @@ func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error - arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { ec.Error(err) @@ -1551,7 +1544,6 @@ func UnmarshalReviewInput(v interface{}) (Review, error) { switch k { case "stars": var err error - it.Stars, err = graphql.UnmarshalInt(v) if err != nil { return it, err @@ -1559,15 +1551,16 @@ func UnmarshalReviewInput(v interface{}) (Review, error) { case "commentary": var err error var ptr1 string + if v != nil { + ptr1, err = graphql.UnmarshalString(v) + it.Commentary = &ptr1 + } - ptr1, err = graphql.UnmarshalString(v) - it.Commentary = &ptr1 if err != nil { return it, err } case "time": var err error - it.Time, err = graphql.UnmarshalTime(v) if err != nil { return it, err diff --git a/example/todo/generated.go b/example/todo/generated.go index b0da0413009..aca76f11764 100644 --- a/example/todo/generated.go +++ b/example/todo/generated.go @@ -101,7 +101,6 @@ func (ec *executionContext) _MyMutation_createTodo(field graphql.CollectedField) var arg0 TodoInput if tmp, ok := field.Args["todo"]; ok { var err error - arg0, err = UnmarshalTodoInput(tmp) if err != nil { ec.Error(err) @@ -120,7 +119,6 @@ func (ec *executionContext) _MyMutation_updateTodo(field graphql.CollectedField) var arg0 int if tmp, ok := field.Args["id"]; ok { var err error - arg0, err = graphql.UnmarshalInt(tmp) if err != nil { ec.Error(err) @@ -130,7 +128,6 @@ func (ec *executionContext) _MyMutation_updateTodo(field graphql.CollectedField) var arg1 map[string]interface{} if tmp, ok := field.Args["changes"]; ok { var err error - arg1, err = graphql.UnmarshalMap(tmp) if err != nil { ec.Error(err) @@ -182,7 +179,6 @@ func (ec *executionContext) _MyQuery_todo(field graphql.CollectedField) graphql. var arg0 int if tmp, ok := field.Args["id"]; ok { var err error - arg0, err = graphql.UnmarshalInt(tmp) if err != nil { ec.Error(err) @@ -264,7 +260,6 @@ func (ec *executionContext) _MyQuery___type(field graphql.CollectedField) graphq var arg0 string if tmp, ok := field.Args["name"]; ok { var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -719,7 +714,6 @@ func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *in var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error - arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { ec.Error(err) @@ -771,7 +765,6 @@ func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error - arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { ec.Error(err) @@ -820,7 +813,6 @@ func UnmarshalTodoInput(v interface{}) (TodoInput, error) { switch k { case "text": var err error - it.Text, err = graphql.UnmarshalString(v) if err != nil { return it, err @@ -828,9 +820,11 @@ func UnmarshalTodoInput(v interface{}) (TodoInput, error) { case "done": var err error var ptr1 bool + if v != nil { + ptr1, err = graphql.UnmarshalBoolean(v) + it.Done = &ptr1 + } - ptr1, err = graphql.UnmarshalBoolean(v) - it.Done = &ptr1 if err != nil { return it, err } diff --git a/example/todo/todo_test.go b/example/todo/todo_test.go index e479ea36663..c7b6529c5d5 100644 --- a/example/todo/todo_test.go +++ b/example/todo/todo_test.go @@ -119,4 +119,13 @@ func TestTodo(t *testing.T) { var resp interface{} c.MustPost(introspection.Query, &resp) }) + + t.Run("null optional field", func(t *testing.T) { + var resp struct { + CreateTodo struct{ Text string } + } + c.MustPost(`mutation { createTodo(todo:{text:"Completed todo", done: null}) { text } }`, &resp) + + require.Equal(t, "Completed todo", resp.CreateTodo.Text) + }) } diff --git a/main.go b/main.go index 8c68ded8e87..695a37e60c5 100644 --- a/main.go +++ b/main.go @@ -104,7 +104,6 @@ func gofmt(filename string, b []byte) []byte { } func write(filename string, b []byte) { - fmt.Println(filename) err := os.MkdirAll(filepath.Dir(filename), 0755) if err != nil { fmt.Fprintln(os.Stderr, "failed to create directory: ", err.Error()) diff --git a/test/generated.go b/test/generated.go index 65f1e182c8f..986c68d217a 100644 --- a/test/generated.go +++ b/test/generated.go @@ -208,7 +208,6 @@ func (ec *executionContext) _Query_nestedInputs(field graphql.CollectedField) gr rawIf2 := rawIf1[idx1].([]interface{}) arg0[idx1] = make([]OuterInput, len(rawIf2)) for idx2 := range rawIf2 { - arg0[idx1][idx2], err = UnmarshalOuterInput(rawIf2[idx2]) } } @@ -225,7 +224,6 @@ func (ec *executionContext) _Query_nestedInputs(field graphql.CollectedField) gr rawIf2 := rawIf1[idx1].([]interface{}) arg0[idx1] = make([]OuterInput, len(rawIf2)) for idx2 := range rawIf2 { - arg0[idx1][idx2], err = UnmarshalOuterInput(rawIf2[idx2]) } } @@ -310,9 +308,11 @@ func (ec *executionContext) _Query_recursive(field graphql.CollectedField) graph if tmp, ok := field.Args["input"]; ok { var err error var ptr1 RecursiveInputSlice + if tmp != nil { + ptr1, err = UnmarshalRecursiveInputSlice(tmp) + arg0 = &ptr1 + } - ptr1, err = UnmarshalRecursiveInputSlice(tmp) - arg0 = &ptr1 if err != nil { ec.Error(err) return graphql.Null @@ -350,7 +350,6 @@ func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql. var arg0 string if tmp, ok := field.Args["name"]; ok { var err error - arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) @@ -805,7 +804,6 @@ func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *in var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error - arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { ec.Error(err) @@ -857,7 +855,6 @@ func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error - arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { ec.Error(err) @@ -932,7 +929,6 @@ func UnmarshalInnerInput(v interface{}) (InnerInput, error) { switch k { case "id": var err error - it.ID, err = graphql.UnmarshalInt(v) if err != nil { return it, err @@ -950,7 +946,6 @@ func UnmarshalOuterInput(v interface{}) (OuterInput, error) { switch k { case "inner": var err error - it.Inner, err = UnmarshalInnerInput(v) if err != nil { return it, err @@ -969,15 +964,20 @@ func UnmarshalRecursiveInputSlice(v interface{}) (RecursiveInputSlice, error) { case "self": var err error var ptr1 []*RecursiveInputSlice - rawIf2 := v.([]interface{}) - ptr1 = make([]*RecursiveInputSlice, len(rawIf2)) - for idx2 := range rawIf2 { - var ptr3 RecursiveInputSlice + if v != nil { + rawIf2 := v.([]interface{}) + ptr1 = make([]*RecursiveInputSlice, len(rawIf2)) + for idx2 := range rawIf2 { + var ptr3 RecursiveInputSlice + if rawIf2[idx2] != nil { + ptr3, err = UnmarshalRecursiveInputSlice(rawIf2[idx2]) + ptr1[idx2] = &ptr3 + } - ptr3, err = UnmarshalRecursiveInputSlice(rawIf2[idx2]) - ptr1[idx2] = &ptr3 + } + it.Self = &ptr1 } - it.Self = &ptr1 + if err != nil { return it, err } From f8add9d2c79ce57f5b7776fd4265f7a72bebc4a3 Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Mon, 19 Mar 2018 12:36:30 +1100 Subject: [PATCH 2/2] remove more unneeded whitespace --- codegen/type.go | 4 ++-- example/scalars/generated.go | 1 - test/generated.go | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/codegen/type.go b/codegen/type.go index 87587a4ec50..cd81c53da19 100644 --- a/codegen/type.go +++ b/codegen/type.go @@ -107,7 +107,7 @@ func (t Type) unmarshal(result, raw string, remainingMods []string, depth int) s return tpl(`{{.rawSlice}} := {{.raw}}.([]interface{}) {{.result}} = make({{.type}}, len({{.rawSlice}})) for {{.index}} := range {{.rawSlice}} { - {{ .next }} + {{ .next -}} }`, map[string]interface{}{ "raw": raw, "rawSlice": rawIf, @@ -128,7 +128,7 @@ func (t Type) unmarshal(result, raw string, remainingMods []string, depth int) s {{ end }} {{- if .t.Marshaler }} {{- .result }}, err = {{ .t.Marshaler.PkgDot }}Unmarshal{{.t.Marshaler.GoType}}({{.raw}}) - {{- else }} + {{- else -}} err = (&{{.result}}).UnmarshalGQL({{.raw}}) {{- end }} {{- if .t.CastType }} diff --git a/example/scalars/generated.go b/example/scalars/generated.go index 703a27babdd..04b74f770e8 100644 --- a/example/scalars/generated.go +++ b/example/scalars/generated.go @@ -741,7 +741,6 @@ func UnmarshalSearchArgs(v interface{}) (SearchArgs, error) { var err error var ptr1 Point if v != nil { - err = (&ptr1).UnmarshalGQL(v) it.Location = &ptr1 } diff --git a/test/generated.go b/test/generated.go index 986c68d217a..10be3232173 100644 --- a/test/generated.go +++ b/test/generated.go @@ -973,7 +973,6 @@ func UnmarshalRecursiveInputSlice(v interface{}) (RecursiveInputSlice, error) { ptr3, err = UnmarshalRecursiveInputSlice(rawIf2[idx2]) ptr1[idx2] = &ptr3 } - } it.Self = &ptr1 }