github.com/99designs/gqlgen@v0.17.45/docs/content/reference/model-generation.md (about) 1 --- 2 title: Model generation 3 description: Examples of ways to alter generated model output 4 linkTitle: Model Generation 5 menu: { main: {parent: 'reference', weight: 10 }} 6 --- 7 8 While we do our best to create Go models that are equivalent to their GraphQL counterparts, it can sometimes be 9 advantageous, or even necessary, to have control over some aspects of this output depending on runtime environment. 10 11 ## json ",omitempty" 12 13 By default, fields that are marked as nullable in the GraphQL schema, e.g. `field: String` rather than `field: String!`, 14 have the [json ",omitempty"](https://pkg.go.dev/encoding/json#Marshal) field tag applied to them. This is probably fine 15 if the downstream consumers of json serialized representations of this model are all written in Go, but obviously this 16 is not always true. 17 18 To that end, you expressly disable the addition of the `,omitempty` json field tag by setting the top-level 19 [config](https://gqlgen.com/config/) field `enable_model_json_omitempty_tag` to `false`: 20 21 ### Examples 22 23 ```graphql 24 # graphql 25 26 type OmitEmptyJsonTagTest { 27 ValueNonNil: String! 28 Value: String 29 } 30 ``` 31 32 Without `enable_model_json_omitempty_tag` configured: 33 34 ```go 35 type OmitEmptyJSONTagTest struct { 36 ValueNonNil string `json:"ValueNonNil" database:"OmitEmptyJsonTagTestValueNonNil"` 37 Value *string `json:"Value,omitempty" database:"OmitEmptyJsonTagTestValue"` 38 } 39 ``` 40 41 With `enable_model_json_omitempty_tag: true` (same as un-configured): 42 43 ```go 44 type OmitEmptyJSONTagTest struct { 45 ValueNonNil string `json:"ValueNonNil" database:"OmitEmptyJsonTagTestValueNonNil"` 46 Value *string `json:"Value,omitempty" database:"OmitEmptyJsonTagTestValue"` 47 } 48 ``` 49 50 With `enable_model_json_omitempty_tag: false`: 51 52 ```go 53 type OmitEmptyJSONTagTest struct { 54 ValueNonNil string `json:"ValueNonNil" database:"OmitEmptyJsonTagTestValueNonNil"` 55 Value *string `json:"Value" database:"OmitEmptyJsonTagTestValue"` 56 } 57 ```