Skip to content

Commit

Permalink
add README.md about enableClientJsonOmitemptyTag
Browse files Browse the repository at this point in the history
  • Loading branch information
abe-tetsu committed Dec 18, 2024
1 parent 4a5bf20 commit fb8792c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ generate:
clientInterfaceName: "GithubGraphQLClient" # Determine the name of the generated client interface
structFieldsAlwaysPointers: true # Optional: Always use pointers for struct fields (default: true). [same as gqlgen](https://github.com/99designs/gqlgen/blob/e1ef86e795e738654c98553b325a248c02c8c2f8/docs/content/config.md?plain=1#L73)
onlyUsedModels: true # Optional: Only generate used models
enableClientJsonOmitemptyTag: true # Optional: Controls whether the "omitempty" option is added to JSON tags (default: true)
```
Execute the following command on same directory for .gqlgenc.yml
Expand Down
6 changes: 3 additions & 3 deletions clientgenv2/source_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ type SourceGenerator struct {
cfg *config.Config
binder *config.Binder
client config.PackageConfig
generateConfig *gqlgencConfig.GenerateConfig
StructSources []*StructSource
GenerateConfig *gqlgencConfig.GenerateConfig
}

func NewSourceGenerator(cfg *config.Config, client config.PackageConfig, generateConfig *gqlgencConfig.GenerateConfig) *SourceGenerator {
Expand All @@ -95,7 +95,7 @@ func NewSourceGenerator(cfg *config.Config, client config.PackageConfig, generat
binder: cfg.NewBinder(),
client: client,
StructSources: []*StructSource{},
GenerateConfig: generateConfig,
generateConfig: generateConfig,
}
}

Expand Down Expand Up @@ -151,7 +151,7 @@ func (r *SourceGenerator) NewResponseField(selection ast.Selection, typeName str
typ := r.binder.CopyModifiersFromAst(selection.Definition.Type, baseType)

jsonTag := fmt.Sprintf(`json:"%s"`, selection.Alias)
if r.GenerateConfig.IsEnableClientJsonOmitemptyTag() && isOptional {
if r.generateConfig.IsEnableClientJsonOmitemptyTag() && isOptional {
jsonTag = fmt.Sprintf(`json:"%s,omitempty"`, selection.Alias)
}
tags := []string{
Expand Down

0 comments on commit fb8792c

Please sign in to comment.