Add "generic" option to the "optional" configuration for handling nullable types (#252)

This is an implementation for #251, it adds a new `"generic"` option for
the `"optional"` configuration, and a companion type
`"optional_generic_type"` which is a fully qualified type with a
placeholder `%` for the generic parameter.

Co-authored-by: Dylan R. Johnston <[email protected]>
Co-authored-by: Ben Kraft <[email protected]>
This commit is contained in:
Dylan R. Johnston
2023-05-06 10:40:03 -07:00
committed by GitHub
co-authored by Dylan R. Johnston Ben Kraft
parent 94b6a71403
commit c61d7acaa5
8 changed files with 279 additions and 12 deletions
+2
View File
@@ -24,6 +24,8 @@ When releasing a new version:
### New features:
- The new `optional: generic` allows using a generic type to represent optionality. See the [documentation](genqlient.yaml) for details.
### Bug fixes:
## v0.6.0
+11
View File
@@ -109,8 +109,19 @@ use_extensions: boolean
# 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.
# - generic: optional fields are generated as type parameters to a generic type
# specified by `optional_generic_type`. E.g. fields with GraphQL type `String`
# will map to the Go type `generic.Type[string]`. This is useful if you have a
# type that mimics the behavior of Option<A> or Maybe<A> in other languages like
# Rust, Java, or Haskell.
optional: value
# Only used when `optional: generic` is set. `example.Type` must be a fully qualified
# generic type with only one generic parameter e.g. atomic.Value[string].
# It must also implement the `encoding/json.Marshaler` and `encoding/json.Unmarshaler`
# interface if you want it to serialize / deserialize properly.
optional_generic_type: github.com/organisation/repository/example.Type
# A map from GraphQL type name to Go fully-qualified type name to override
# the Go type genqlient will use for this GraphQL type.
#