Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Note that genqlient now requires Go 1.23 or higher, and is tested through Go 1.2

### Bug fixes:

- fixed `pointer_omitempty` not being applied to list types when `use_struct_references` is enabled. List fields like `[String!]` now correctly get the `omitempty` JSON tag.
- fixed minor typos and grammatical issues across the project

## v0.8.1
Expand Down
15 changes: 14 additions & 1 deletion generate/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,20 @@ func (g *generator) convertType(
// Type is a list.
elem, err := g.convertType(
namePrefix, typ.Elem, selectionSet, options, queryOptions)
return &goSliceType{elem}, err
// For list types, we need to handle pointer_omitempty here because
// the code below won't be executed for slices.
// If the list itself is nullable (e.g., [String!] vs [String!]!),
// and pointer_omitempty is configured, we should set omitempty.
if err != nil {
return nil, err
}
if g.Config.Optional == "pointer_omitempty" && !typ.NonNull {
if options.Omitempty == nil {
oe := true
options.Omitempty = &oe
}
}
return &goSliceType{elem}, nil
}

// If this is a builtin type or custom scalar, just refer to it.
Expand Down
1 change: 1 addition & 0 deletions generate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func TestGenerateWithConfig(t *testing.T) {
"PointersOmitEmpty.graphql",
"Omitempty.graphql",
"ListInput.graphql",
"ListInputOmitempty.graphql",
}, &Config{
Optional: "pointer_omitempty",
Bindings: map[string]*TypeBinding{
Expand Down
5 changes: 5 additions & 0 deletions generate/testdata/queries/ListInputOmitempty.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query ListInputOmitemptyQuery($names: [String!]) {
user(query: {names: $names}) {
id
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"operations": [
{
"operationName": "ListInputOmitemptyQuery",
"query": "\nquery ListInputOmitemptyQuery ($names: [String!]) {\n\tuser(query: {names:$names}) {\n\t\tid\n\t}\n}\n",
"sourceLocation": "testdata/queries/ListInputOmitempty.graphql"
}
]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.