From 0bbc7f8ca2b460a9c7e4c17326a84b607546ee52 Mon Sep 17 00:00:00 2001 From: Steve Coffman Date: Thu, 9 Mar 2023 14:52:28 -0500 Subject: [PATCH] Add omitempty to struct tags for nullable types (#2436) Signed-off-by: Steve Coffman --- _examples/scalars/model/generated.go | 2 +- _examples/selection/models_gen.go | 8 ++-- _examples/starwars/models/generated.go | 2 +- _examples/todo/models_gen.go | 2 +- codegen/testserver/followschema/models-gen.go | 38 ++++++++--------- codegen/testserver/singlefile/models-gen.go | 38 ++++++++--------- integration/models-go/generated.go | 12 +++--- .../entityresolver/generated/models.go | 4 +- plugin/modelgen/models.go | 9 +++- plugin/modelgen/models_test.go | 16 +++---- plugin/modelgen/out/generated.go | 42 +++++++++---------- .../modelgen/out_struct_pointers/generated.go | 42 +++++++++---------- .../filetemplate/out/schema.custom.go | 2 +- .../followschema/out/schema.resolvers.go | 2 +- 14 files changed, 113 insertions(+), 106 deletions(-) diff --git a/_examples/scalars/model/generated.go b/_examples/scalars/model/generated.go index 34fc602cc4..c3b4b2c55b 100644 --- a/_examples/scalars/model/generated.go +++ b/_examples/scalars/model/generated.go @@ -8,5 +8,5 @@ import ( type Address struct { ID external.ObjectID `json:"id"` - Location *Point `json:"location"` + Location *Point `json:"location,omitempty"` } diff --git a/_examples/selection/models_gen.go b/_examples/selection/models_gen.go index 3a66264849..3ed9400b11 100644 --- a/_examples/selection/models_gen.go +++ b/_examples/selection/models_gen.go @@ -15,8 +15,8 @@ type Event interface { type Like struct { Reaction string `json:"reaction"` Sent time.Time `json:"sent"` - Selection []string `json:"selection"` - Collected []string `json:"collected"` + Selection []string `json:"selection,omitempty"` + Collected []string `json:"collected,omitempty"` } func (Like) IsEvent() {} @@ -44,8 +44,8 @@ func (this Like) GetCollected() []string { type Post struct { Message string `json:"message"` Sent time.Time `json:"sent"` - Selection []string `json:"selection"` - Collected []string `json:"collected"` + Selection []string `json:"selection,omitempty"` + Collected []string `json:"collected,omitempty"` } func (Post) IsEvent() {} diff --git a/_examples/starwars/models/generated.go b/_examples/starwars/models/generated.go index 78d4394509..cdd4c86a89 100644 --- a/_examples/starwars/models/generated.go +++ b/_examples/starwars/models/generated.go @@ -23,7 +23,7 @@ type SearchResult interface { type FriendsEdge struct { Cursor string `json:"cursor"` - Node Character `json:"node"` + Node Character `json:"node,omitempty"` } type PageInfo struct { diff --git a/_examples/todo/models_gen.go b/_examples/todo/models_gen.go index 74a1c0da57..bdc684a999 100644 --- a/_examples/todo/models_gen.go +++ b/_examples/todo/models_gen.go @@ -13,7 +13,7 @@ type TodoInput struct { // The body text Text string `json:"text"` // Is it done already? - Done *bool `json:"done"` + Done *bool `json:"done,omitempty"` } type Role string diff --git a/codegen/testserver/followschema/models-gen.go b/codegen/testserver/followschema/models-gen.go index 875941bef2..afa4df98d0 100644 --- a/codegen/testserver/followschema/models-gen.go +++ b/codegen/testserver/followschema/models-gen.go @@ -54,17 +54,17 @@ func (this Cat) GetSpecies() string { return this.Species } func (this Cat) GetSize() *Size { return this.Size } type CheckIssue896 struct { - ID *int `json:"id"` + ID *int `json:"id,omitempty"` } type ContentPost struct { - Foo *string `json:"foo"` + Foo *string `json:"foo,omitempty"` } func (ContentPost) IsContentChild() {} type ContentUser struct { - Foo *string `json:"foo"` + Foo *string `json:"foo,omitempty"` } func (ContentUser) IsContentChild() {} @@ -75,13 +75,13 @@ type Coordinates struct { } type DefaultInput struct { - FalsyBoolean *bool `json:"falsyBoolean"` - TruthyBoolean *bool `json:"truthyBoolean"` + FalsyBoolean *bool `json:"falsyBoolean,omitempty"` + TruthyBoolean *bool `json:"truthyBoolean,omitempty"` } type DefaultParametersMirror struct { - FalsyBoolean *bool `json:"falsyBoolean"` - TruthyBoolean *bool `json:"truthyBoolean"` + FalsyBoolean *bool `json:"falsyBoolean,omitempty"` + TruthyBoolean *bool `json:"truthyBoolean,omitempty"` } type Dog struct { @@ -95,11 +95,11 @@ func (this Dog) GetSpecies() string { return this.Species } func (this Dog) GetSize() *Size { return this.Size } type EmbeddedDefaultScalar struct { - Value *string `json:"value"` + Value *string `json:"value,omitempty"` } type FieldsOrderPayload struct { - FirstFieldValue *string `json:"firstFieldValue"` + FirstFieldValue *string `json:"firstFieldValue,omitempty"` } type InnerDirectives struct { @@ -116,10 +116,10 @@ type InnerObject struct { type InputDirectives struct { Text string `json:"text"` - NullableText *string `json:"nullableText"` + NullableText *string `json:"nullableText,omitempty"` Inner *InnerDirectives `json:"inner"` - InnerNullable *InnerDirectives `json:"innerNullable"` - ThirdParty *ThirdParty `json:"thirdParty"` + InnerNullable *InnerDirectives `json:"innerNullable,omitempty"` + ThirdParty *ThirdParty `json:"thirdParty,omitempty"` } type InputWithEnumValue struct { @@ -145,12 +145,12 @@ type NestedInput struct { } type NestedMapInput struct { - Map map[string]interface{} `json:"map"` + Map map[string]interface{} `json:"map,omitempty"` } type ObjectDirectives struct { Text string `json:"text"` - NullableText *string `json:"nullableText"` + NullableText *string `json:"nullableText,omitempty"` Order []string `json:"order"` } @@ -164,7 +164,7 @@ type OuterObject struct { type Pet struct { ID int `json:"id"` - Friends []*Pet `json:"friends"` + Friends []*Pet `json:"friends,omitempty"` } type Size struct { @@ -173,8 +173,8 @@ type Size struct { } type Slices struct { - Test1 []*string `json:"test1"` - Test2 []string `json:"test2"` + Test1 []*string `json:"test1,omitempty"` + Test2 []string `json:"test2,omitempty"` Test3 []*string `json:"test3"` Test4 []string `json:"test4"` } @@ -187,8 +187,8 @@ type User struct { ID int `json:"id"` Friends []*User `json:"friends"` Created time.Time `json:"created"` - Updated *time.Time `json:"updated"` - Pets []*Pet `json:"pets"` + Updated *time.Time `json:"updated,omitempty"` + Pets []*Pet `json:"pets,omitempty"` } type ValidInput struct { diff --git a/codegen/testserver/singlefile/models-gen.go b/codegen/testserver/singlefile/models-gen.go index 5ab72058e3..098426262f 100644 --- a/codegen/testserver/singlefile/models-gen.go +++ b/codegen/testserver/singlefile/models-gen.go @@ -54,17 +54,17 @@ func (this Cat) GetSpecies() string { return this.Species } func (this Cat) GetSize() *Size { return this.Size } type CheckIssue896 struct { - ID *int `json:"id"` + ID *int `json:"id,omitempty"` } type ContentPost struct { - Foo *string `json:"foo"` + Foo *string `json:"foo,omitempty"` } func (ContentPost) IsContentChild() {} type ContentUser struct { - Foo *string `json:"foo"` + Foo *string `json:"foo,omitempty"` } func (ContentUser) IsContentChild() {} @@ -75,13 +75,13 @@ type Coordinates struct { } type DefaultInput struct { - FalsyBoolean *bool `json:"falsyBoolean"` - TruthyBoolean *bool `json:"truthyBoolean"` + FalsyBoolean *bool `json:"falsyBoolean,omitempty"` + TruthyBoolean *bool `json:"truthyBoolean,omitempty"` } type DefaultParametersMirror struct { - FalsyBoolean *bool `json:"falsyBoolean"` - TruthyBoolean *bool `json:"truthyBoolean"` + FalsyBoolean *bool `json:"falsyBoolean,omitempty"` + TruthyBoolean *bool `json:"truthyBoolean,omitempty"` } type Dog struct { @@ -95,11 +95,11 @@ func (this Dog) GetSpecies() string { return this.Species } func (this Dog) GetSize() *Size { return this.Size } type EmbeddedDefaultScalar struct { - Value *string `json:"value"` + Value *string `json:"value,omitempty"` } type FieldsOrderPayload struct { - FirstFieldValue *string `json:"firstFieldValue"` + FirstFieldValue *string `json:"firstFieldValue,omitempty"` } type InnerDirectives struct { @@ -116,10 +116,10 @@ type InnerObject struct { type InputDirectives struct { Text string `json:"text"` - NullableText *string `json:"nullableText"` + NullableText *string `json:"nullableText,omitempty"` Inner *InnerDirectives `json:"inner"` - InnerNullable *InnerDirectives `json:"innerNullable"` - ThirdParty *ThirdParty `json:"thirdParty"` + InnerNullable *InnerDirectives `json:"innerNullable,omitempty"` + ThirdParty *ThirdParty `json:"thirdParty,omitempty"` } type InputWithEnumValue struct { @@ -145,12 +145,12 @@ type NestedInput struct { } type NestedMapInput struct { - Map map[string]interface{} `json:"map"` + Map map[string]interface{} `json:"map,omitempty"` } type ObjectDirectives struct { Text string `json:"text"` - NullableText *string `json:"nullableText"` + NullableText *string `json:"nullableText,omitempty"` Order []string `json:"order"` } @@ -164,7 +164,7 @@ type OuterObject struct { type Pet struct { ID int `json:"id"` - Friends []*Pet `json:"friends"` + Friends []*Pet `json:"friends,omitempty"` } type Size struct { @@ -173,8 +173,8 @@ type Size struct { } type Slices struct { - Test1 []*string `json:"test1"` - Test2 []string `json:"test2"` + Test1 []*string `json:"test1,omitempty"` + Test2 []string `json:"test2,omitempty"` Test3 []*string `json:"test3"` Test4 []string `json:"test4"` } @@ -187,8 +187,8 @@ type User struct { ID int `json:"id"` Friends []*User `json:"friends"` Created time.Time `json:"created"` - Updated *time.Time `json:"updated"` - Pets []*Pet `json:"pets"` + Updated *time.Time `json:"updated,omitempty"` + Pets []*Pet `json:"pets,omitempty"` } type ValidInput struct { diff --git a/integration/models-go/generated.go b/integration/models-go/generated.go index 7392b76dcc..d3c0701ecb 100644 --- a/integration/models-go/generated.go +++ b/integration/models-go/generated.go @@ -10,15 +10,15 @@ import ( type DateFilter struct { Value string `json:"value"` - Timezone *string `json:"timezone"` - Op *DateFilterOp `json:"op"` + Timezone *string `json:"timezone,omitempty"` + Op *DateFilterOp `json:"op,omitempty"` } type ListCoercion struct { - EnumVal []*ErrorType `json:"enumVal"` - StrVal []*string `json:"strVal"` - IntVal []*int `json:"intVal"` - ScalarVal []map[string]interface{} `json:"scalarVal"` + EnumVal []*ErrorType `json:"enumVal,omitempty"` + StrVal []*string `json:"strVal,omitempty"` + IntVal []*int `json:"intVal,omitempty"` + ScalarVal []map[string]interface{} `json:"scalarVal,omitempty"` } type DateFilterOp string diff --git a/plugin/federation/testdata/entityresolver/generated/models.go b/plugin/federation/testdata/entityresolver/generated/models.go index 262047b401..5c3c09a496 100644 --- a/plugin/federation/testdata/entityresolver/generated/models.go +++ b/plugin/federation/testdata/entityresolver/generated/models.go @@ -107,7 +107,7 @@ func (PlanetRequiresNested) IsEntity() {} type World struct { Foo string `json:"foo"` Bar int `json:"bar"` - Hello *Hello `json:"hello"` + Hello *Hello `json:"hello,omitempty"` } func (World) IsEntity() {} @@ -121,7 +121,7 @@ func (WorldName) IsEntity() {} type WorldWithMultipleKeys struct { Foo string `json:"foo"` Bar int `json:"bar"` - Hello *Hello `json:"hello"` + Hello *Hello `json:"hello,omitempty"` } func (WorldWithMultipleKeys) IsEntity() {} diff --git a/plugin/modelgen/models.go b/plugin/modelgen/models.go index 5a5842c977..855ed1001f 100644 --- a/plugin/modelgen/models.go +++ b/plugin/modelgen/models.go @@ -371,7 +371,7 @@ func (m *Plugin) generateFields(cfg *config.Config, schemaType *ast.Definition) GoName: name, Type: typ, Description: field.Description, - Tag: `json:"` + field.Name + `"`, + Tag: getStructTagFromField(field), } if m.FieldHook != nil { @@ -388,6 +388,13 @@ func (m *Plugin) generateFields(cfg *config.Config, schemaType *ast.Definition) return fields, nil } +func getStructTagFromField(field *ast.FieldDefinition) string { + if !field.Type.NonNull { + return `json:"` + field.Name + `,omitempty"` + } + return `json:"` + field.Name + `"` +} + // GoTagFieldHook prepends the goTag directive to the generated Field f. // When applying the Tag to the field, the field // name is used if no value argument is present. diff --git a/plugin/modelgen/models_test.go b/plugin/modelgen/models_test.go index 42bc3d63db..f4f3f35834 100644 --- a/plugin/modelgen/models_test.go +++ b/plugin/modelgen/models_test.go @@ -65,13 +65,13 @@ func TestModelGeneration(t *testing.T) { expectedTags := []string{ `json:"missing2" database:"MissingTypeNotNullmissing2"`, - `json:"name" database:"MissingInputname"`, - `json:"missing2" database:"MissingTypeNullablemissing2"`, - `json:"name" database:"TypeWithDescriptionname"`, + `json:"name,omitempty" database:"MissingInputname"`, + `json:"missing2,omitempty" database:"MissingTypeNullablemissing2"`, + `json:"name,omitempty" database:"TypeWithDescriptionname"`, } for _, tag := range expectedTags { - require.True(t, strings.Contains(fileText, tag)) + require.True(t, strings.Contains(fileText, tag), "\nexpected:\n"+tag+"\ngot\n"+fileText) } }) @@ -82,10 +82,10 @@ func TestModelGeneration(t *testing.T) { fileText := string(file) expectedTags := []string{ - `json:"name" anotherTag:"tag"`, - `json:"enum" yetAnotherTag:"12"`, - `json:"noVal" yaml:"noVal" repeated:"true"`, - `json:"repeated" someTag:"value" repeated:"true"`, + `json:"name,omitempty" anotherTag:"tag"`, + `json:"enum,omitempty" yetAnotherTag:"12"`, + `json:"noVal,omitempty" yaml:"noVal" repeated:"true"`, + `json:"repeated,omitempty" someTag:"value" repeated:"true"`, } for _, tag := range expectedTags { diff --git a/plugin/modelgen/out/generated.go b/plugin/modelgen/out/generated.go index c968c466dc..b382a44a39 100644 --- a/plugin/modelgen/out/generated.go +++ b/plugin/modelgen/out/generated.go @@ -74,7 +74,7 @@ type CDImplemented struct { A string `json:"a" database:"CDImplementeda"` B int `json:"b" database:"CDImplementedb"` C bool `json:"c" database:"CDImplementedc"` - D *string `json:"d" database:"CDImplementedd"` + D *string `json:"d,omitempty" database:"CDImplementedd"` } func (CDImplemented) IsC() {} @@ -91,30 +91,30 @@ func (this CDImplemented) GetD() *string { return this.D } func (CDImplemented) IsB() {} type CyclicalA struct { - FieldOne *CyclicalB `json:"field_one" database:"CyclicalAfield_one"` - FieldTwo *CyclicalB `json:"field_two" database:"CyclicalAfield_two"` - FieldThree *CyclicalB `json:"field_three" database:"CyclicalAfield_three"` + FieldOne *CyclicalB `json:"field_one,omitempty" database:"CyclicalAfield_one"` + FieldTwo *CyclicalB `json:"field_two,omitempty" database:"CyclicalAfield_two"` + FieldThree *CyclicalB `json:"field_three,omitempty" database:"CyclicalAfield_three"` FieldFour string `json:"field_four" database:"CyclicalAfield_four"` } type CyclicalB struct { - FieldOne *CyclicalA `json:"field_one" database:"CyclicalBfield_one"` - FieldTwo *CyclicalA `json:"field_two" database:"CyclicalBfield_two"` - FieldThree *CyclicalA `json:"field_three" database:"CyclicalBfield_three"` - FieldFour *CyclicalA `json:"field_four" database:"CyclicalBfield_four"` + FieldOne *CyclicalA `json:"field_one,omitempty" database:"CyclicalBfield_one"` + FieldTwo *CyclicalA `json:"field_two,omitempty" database:"CyclicalBfield_two"` + FieldThree *CyclicalA `json:"field_three,omitempty" database:"CyclicalBfield_three"` + FieldFour *CyclicalA `json:"field_four,omitempty" database:"CyclicalBfield_four"` FieldFive string `json:"field_five" database:"CyclicalBfield_five"` } type FieldMutationHook struct { - Name *string `json:"name" anotherTag:"tag" database:"FieldMutationHookname"` - Enum *ExistingEnum `json:"enum" yetAnotherTag:"12" database:"FieldMutationHookenum"` - NoVal *string `json:"noVal" yaml:"noVal" repeated:"true" database:"FieldMutationHooknoVal"` - Repeated *string `json:"repeated" someTag:"value" repeated:"true" database:"FieldMutationHookrepeated"` + Name *string `json:"name,omitempty" anotherTag:"tag" database:"FieldMutationHookname"` + Enum *ExistingEnum `json:"enum,omitempty" yetAnotherTag:"12" database:"FieldMutationHookenum"` + NoVal *string `json:"noVal,omitempty" yaml:"noVal" repeated:"true" database:"FieldMutationHooknoVal"` + Repeated *string `json:"repeated,omitempty" someTag:"value" repeated:"true" database:"FieldMutationHookrepeated"` } type ImplArrayOfA struct { TrickyField []*CDImplemented `json:"trickyField" database:"ImplArrayOfAtrickyField"` - TrickyFieldPointer []*CDImplemented `json:"trickyFieldPointer" database:"ImplArrayOfAtrickyFieldPointer"` + TrickyFieldPointer []*CDImplemented `json:"trickyFieldPointer,omitempty" database:"ImplArrayOfAtrickyFieldPointer"` } func (ImplArrayOfA) IsArrayOfA() {} @@ -140,8 +140,8 @@ func (this ImplArrayOfA) GetTrickyFieldPointer() []A { } type MissingInput struct { - Name *string `json:"name" database:"MissingInputname"` - Enum *MissingEnum `json:"enum" database:"MissingInputenum"` + Name *string `json:"name,omitempty" database:"MissingInputname"` + Enum *MissingEnum `json:"enum,omitempty" database:"MissingInputenum"` } type MissingTypeNotNull struct { @@ -162,11 +162,11 @@ func (MissingTypeNotNull) IsMissingUnion() {} func (MissingTypeNotNull) IsExistingUnion() {} type MissingTypeNullable struct { - Name *string `json:"name" database:"MissingTypeNullablename"` - Enum *MissingEnum `json:"enum" database:"MissingTypeNullableenum"` - Int MissingInterface `json:"int" database:"MissingTypeNullableint"` - Existing *ExistingType `json:"existing" database:"MissingTypeNullableexisting"` - Missing2 *MissingTypeNotNull `json:"missing2" database:"MissingTypeNullablemissing2"` + Name *string `json:"name,omitempty" database:"MissingTypeNullablename"` + Enum *MissingEnum `json:"enum,omitempty" database:"MissingTypeNullableenum"` + Int MissingInterface `json:"int,omitempty" database:"MissingTypeNullableint"` + Existing *ExistingType `json:"existing,omitempty" database:"MissingTypeNullableexisting"` + Missing2 *MissingTypeNotNull `json:"missing2,omitempty" database:"MissingTypeNullablemissing2"` } func (MissingTypeNullable) IsMissingInterface() {} @@ -202,7 +202,7 @@ type RenameFieldTest struct { // TypeWithDescription is a type with a description type TypeWithDescription struct { - Name *string `json:"name" database:"TypeWithDescriptionname"` + Name *string `json:"name,omitempty" database:"TypeWithDescriptionname"` } func (TypeWithDescription) IsUnionWithDescription() {} diff --git a/plugin/modelgen/out_struct_pointers/generated.go b/plugin/modelgen/out_struct_pointers/generated.go index 7b414f6dd5..7bcbc26dd6 100644 --- a/plugin/modelgen/out_struct_pointers/generated.go +++ b/plugin/modelgen/out_struct_pointers/generated.go @@ -61,7 +61,7 @@ type CDImplemented struct { A string `json:"a" database:"CDImplementeda"` B int `json:"b" database:"CDImplementedb"` C bool `json:"c" database:"CDImplementedc"` - D *string `json:"d" database:"CDImplementedd"` + D *string `json:"d,omitempty" database:"CDImplementedd"` } func (CDImplemented) IsC() {} @@ -73,37 +73,37 @@ func (CDImplemented) IsD() {} func (CDImplemented) IsB() {} type CyclicalA struct { - FieldOne *CyclicalB `json:"field_one" database:"CyclicalAfield_one"` - FieldTwo *CyclicalB `json:"field_two" database:"CyclicalAfield_two"` - FieldThree *CyclicalB `json:"field_three" database:"CyclicalAfield_three"` + FieldOne *CyclicalB `json:"field_one,omitempty" database:"CyclicalAfield_one"` + FieldTwo *CyclicalB `json:"field_two,omitempty" database:"CyclicalAfield_two"` + FieldThree *CyclicalB `json:"field_three,omitempty" database:"CyclicalAfield_three"` FieldFour string `json:"field_four" database:"CyclicalAfield_four"` } type CyclicalB struct { - FieldOne *CyclicalA `json:"field_one" database:"CyclicalBfield_one"` - FieldTwo *CyclicalA `json:"field_two" database:"CyclicalBfield_two"` - FieldThree *CyclicalA `json:"field_three" database:"CyclicalBfield_three"` - FieldFour *CyclicalA `json:"field_four" database:"CyclicalBfield_four"` + FieldOne *CyclicalA `json:"field_one,omitempty" database:"CyclicalBfield_one"` + FieldTwo *CyclicalA `json:"field_two,omitempty" database:"CyclicalBfield_two"` + FieldThree *CyclicalA `json:"field_three,omitempty" database:"CyclicalBfield_three"` + FieldFour *CyclicalA `json:"field_four,omitempty" database:"CyclicalBfield_four"` FieldFive string `json:"field_five" database:"CyclicalBfield_five"` } type FieldMutationHook struct { - Name *string `json:"name" anotherTag:"tag" database:"FieldMutationHookname"` - Enum *ExistingEnum `json:"enum" yetAnotherTag:"12" database:"FieldMutationHookenum"` - NoVal *string `json:"noVal" yaml:"noVal" repeated:"true" database:"FieldMutationHooknoVal"` - Repeated *string `json:"repeated" someTag:"value" repeated:"true" database:"FieldMutationHookrepeated"` + Name *string `json:"name,omitempty" anotherTag:"tag" database:"FieldMutationHookname"` + Enum *ExistingEnum `json:"enum,omitempty" yetAnotherTag:"12" database:"FieldMutationHookenum"` + NoVal *string `json:"noVal,omitempty" yaml:"noVal" repeated:"true" database:"FieldMutationHooknoVal"` + Repeated *string `json:"repeated,omitempty" someTag:"value" repeated:"true" database:"FieldMutationHookrepeated"` } type ImplArrayOfA struct { TrickyField []*CDImplemented `json:"trickyField" database:"ImplArrayOfAtrickyField"` - TrickyFieldPointer []*CDImplemented `json:"trickyFieldPointer" database:"ImplArrayOfAtrickyFieldPointer"` + TrickyFieldPointer []*CDImplemented `json:"trickyFieldPointer,omitempty" database:"ImplArrayOfAtrickyFieldPointer"` } func (ImplArrayOfA) IsArrayOfA() {} type MissingInput struct { - Name *string `json:"name" database:"MissingInputname"` - Enum *MissingEnum `json:"enum" database:"MissingInputenum"` + Name *string `json:"name,omitempty" database:"MissingInputname"` + Enum *MissingEnum `json:"enum,omitempty" database:"MissingInputenum"` } type MissingTypeNotNull struct { @@ -123,11 +123,11 @@ func (MissingTypeNotNull) IsMissingUnion() {} func (MissingTypeNotNull) IsExistingUnion() {} type MissingTypeNullable struct { - Name *string `json:"name" database:"MissingTypeNullablename"` - Enum *MissingEnum `json:"enum" database:"MissingTypeNullableenum"` - Int MissingInterface `json:"int" database:"MissingTypeNullableint"` - Existing *ExistingType `json:"existing" database:"MissingTypeNullableexisting"` - Missing2 *MissingTypeNotNull `json:"missing2" database:"MissingTypeNullablemissing2"` + Name *string `json:"name,omitempty" database:"MissingTypeNullablename"` + Enum *MissingEnum `json:"enum,omitempty" database:"MissingTypeNullableenum"` + Int MissingInterface `json:"int,omitempty" database:"MissingTypeNullableint"` + Existing *ExistingType `json:"existing,omitempty" database:"MissingTypeNullableexisting"` + Missing2 *MissingTypeNotNull `json:"missing2,omitempty" database:"MissingTypeNullablemissing2"` } func (MissingTypeNullable) IsMissingInterface() {} @@ -162,7 +162,7 @@ type RenameFieldTest struct { // TypeWithDescription is a type with a description type TypeWithDescription struct { - Name *string `json:"name" database:"TypeWithDescriptionname"` + Name *string `json:"name,omitempty" database:"TypeWithDescriptionname"` } func (TypeWithDescription) IsUnionWithDescription() {} diff --git a/plugin/resolvergen/testdata/filetemplate/out/schema.custom.go b/plugin/resolvergen/testdata/filetemplate/out/schema.custom.go index a1c4df3617..89f44a10a1 100644 --- a/plugin/resolvergen/testdata/filetemplate/out/schema.custom.go +++ b/plugin/resolvergen/testdata/filetemplate/out/schema.custom.go @@ -2,7 +2,7 @@ package customresolver // This file will be automatically regenerated based on the schema, any resolver implementations // will be copied through when generating and any unknown code will be moved to the end. -// Code generated by github.com/99designs/gqlgen version v0.17.25-dev +// Code generated by github.com/99designs/gqlgen version v0.17.26-dev import ( "context" diff --git a/plugin/resolvergen/testdata/followschema/out/schema.resolvers.go b/plugin/resolvergen/testdata/followschema/out/schema.resolvers.go index a42326cf3e..3819d55914 100644 --- a/plugin/resolvergen/testdata/followschema/out/schema.resolvers.go +++ b/plugin/resolvergen/testdata/followschema/out/schema.resolvers.go @@ -2,7 +2,7 @@ package customresolver // This file will be automatically regenerated based on the schema, any resolver implementations // will be copied through when generating and any unknown code will be moved to the end. -// Code generated by github.com/99designs/gqlgen version v0.17.25-dev +// Code generated by github.com/99designs/gqlgen version v0.17.26-dev import ( "context"