Skip to content

Commit

Permalink
Generate slices containing all enum values (#350)
Browse files Browse the repository at this point in the history
It would be useful to generate slices containing all enum values for
each enum type. Then there will be no need to maintain such kind of
slices manually.

Co-authored-by: dikov.e <[email protected]>
  • Loading branch information
Zhenya750 and dikov.e authored Aug 19, 2024
1 parent 7a9d84f commit 4466fc1
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ When releasing a new version:
- genqlient now supports subscriptions; the websocket protocol is by default `graphql-transport-ws` but can be set to another value.
See the [documentation](FAQ.md) for how to `subscribe to an API 'subscription' endpoint`.
- genqlient now supports double-star globs for schema and query files; see [`genqlient.yaml` docs](genqlient.yaml) for more.
- genqlient now generates slices containing all enum values for each enum type.

### Bug fixes:

Expand Down

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

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

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

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

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

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

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

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

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

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

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

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

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

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

7 changes: 7 additions & 0 deletions generate/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ func (typ *goEnumType) WriteDefinition(w io.Writer, g *generator) error {
val.GoName, typ.GoName, val.GraphQLName)
}
fmt.Fprintf(w, ")\n")

// Add slice with all enums.
fmt.Fprintf(w, "var All%s = []%s{\n", typ.GoName, typ.GoName)
for _, val := range typ.Values {
fmt.Fprintf(w, "%s,\n", val.GoName)
}
fmt.Fprintf(w, "}\n")
return nil
}

Expand Down
5 changes: 5 additions & 0 deletions internal/integration/generated.go

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

0 comments on commit 4466fc1

Please sign in to comment.