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:
Chris Connelly
2022-05-24 12:24:06 -07:00
committed by GitHub
parent 3685f3f66b
commit 37fa3d6e7c
7 changed files with 336 additions and 17 deletions
+17
View File
@@ -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.
#