master
master v0.17.45 v0.17.44 v0.17.43 v0.17.42 v0.17.41 v0.17.40 v0.17.39 v0.17.38 v0.17.37 v0.17.36 v0.17.35 v0.17.34 v0.17.33 v0.17.32 v0.17.31 v0.17.30 v0.17.29 v0.17.28 v0.17.27 v0.17.26

Model Generation

Model generation
[edit]
You are looking at the docs for the unreleased master branch. The latest version is v0.17.45.

While we do our best to create Go models that are equivalent to their GraphQL counterparts, it can sometimes be advantageous, or even necessary, to have control over some aspects of this output depending on runtime environment.

json “,omitempty”

By default, fields that are marked as nullable in the GraphQL schema, e.g. field: String rather than field: String!, have the json “,omitempty” field tag applied to them. This is probably fine if the downstream consumers of json serialized representations of this model are all written in Go, but obviously this is not always true.

To that end, you expressly disable the addition of the ,omitempty json field tag by setting the top-level config field enable_model_json_omitempty_tag to false:

Examples

# graphql

type OmitEmptyJsonTagTest {
    ValueNonNil: String!
    Value: String
}

Without enable_model_json_omitempty_tag configured:

type OmitEmptyJSONTagTest struct {
	ValueNonNil string  `json:"ValueNonNil" database:"OmitEmptyJsonTagTestValueNonNil"`
	Value       *string `json:"Value,omitempty" database:"OmitEmptyJsonTagTestValue"`
}

With enable_model_json_omitempty_tag: true (same as un-configured):

type OmitEmptyJSONTagTest struct {
	ValueNonNil string  `json:"ValueNonNil" database:"OmitEmptyJsonTagTestValueNonNil"`
	Value       *string `json:"Value,omitempty" database:"OmitEmptyJsonTagTestValue"`
}

With enable_model_json_omitempty_tag: false:

type OmitEmptyJSONTagTest struct {
	ValueNonNil string  `json:"ValueNonNil" database:"OmitEmptyJsonTagTestValueNonNil"`
	Value       *string `json:"Value" database:"OmitEmptyJsonTagTestValue"`
}