Add support for mapping all nullable types as pointers (#198)
This implements the approach suggested in https://github.com/Khan/genqlient/issues/178#issuecomment-1077559343. See the added documentation for the full behavior.
This commit is contained in:
@@ -31,6 +31,7 @@ When releasing a new version:
|
||||
- You can now enable `use_extensions` in the configuration file, to receive extensions returned by the GraphQL API server. Generated functions will return extensions as `map[string]interface{}`, if enabled.
|
||||
- You can now use `graphql.NewClientUsingGet` to create a client that uses query parameters to pass the query to the GraphQL API server.
|
||||
- In config files, `schema`, `operations`, and `generated` can now be absolute paths.
|
||||
- You can now configure how nullable types are mapped to Go types in the configuration file. Specifically, you can set `optional: pointer` to have all nullable GraphQL arguments, input fields, and output fields map to pointers.
|
||||
|
||||
### Bug fixes:
|
||||
|
||||
|
||||
@@ -98,6 +98,23 @@ use_struct_references: boolean
|
||||
use_extensions: boolean
|
||||
|
||||
|
||||
# Customize how optional fields are handled.
|
||||
optional:
|
||||
# Customize how models are generated for optional fields. This can currently
|
||||
# be set to one of the following values:
|
||||
# - value (default): optional fields are generated as values, the same as
|
||||
# non-optional fields. E.g. fields with GraphQL types `String` or `String!`
|
||||
# will both map to the Go type `string`. When values are absent in
|
||||
# responses the zero value will be used.
|
||||
# - pointer: optional fields are generated as pointers. E.g. fields with
|
||||
# GraphQL type `String` will map to the Go type `*string`. When values are
|
||||
# absent in responses `nil` will be used. Optional list fields do not use
|
||||
# pointers-to-slices, so the GraphQL type `[String]` will map to the Go
|
||||
# type `[]*string`, not `*[]*string`; GraphQL null and empty list simply
|
||||
# map to Go nil- and empty-slice.
|
||||
output: value
|
||||
|
||||
|
||||
# A map from GraphQL type name to Go fully-qualified type name to override
|
||||
# the Go type genqlient will use for this GraphQL type.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user