Add an option to handle enums with ugly casing (#270)

There are a bunch of places in genqlient where we just kind of hope you
don't have ridiculous casing conflicts in your schema. Apparently with
enum values there are actual schemas that have this problem! Now we have
an option to disable. I ended up putting it all under `casing` instead
of in `bindings` so we can clearly document the list of algorithms we
support, and so we can have an `all_enums` value if you're working with
a schema with a lot of this; in the future we may want to add similar
behavior for types/fields, add more possible algorithms (e.g. to make
things unexported), etc.

I added tests for the new feature, although the way the tests are set up
it wasn't convenient to do so for a schema where this is actually
required. I also added a check for case conflicts that points you to
this option. (I don't want to do it automatically for reasons described
in the issue; mainly it just seemed a bit too magical.)

Fixes #265.
This commit is contained in:
Ben Kraft
2023-05-07 12:15:13 -07:00
committed by GitHub
parent 9b2f16c088
commit ff790e1c06
16 changed files with 375 additions and 17 deletions
+1
View File
@@ -25,6 +25,7 @@ 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.
- For schemas with enum values that differ only in casing, it's now possible to disable smart-casing in genqlient.yaml; see the [documentation](genqlient.yaml) for `casing` for details.
### Bug fixes:
+21
View File
@@ -227,3 +227,24 @@ bindings:
# Explicit entries in bindings take precedence over all package bindings.
package_bindings:
- package: github.com/you/yourpkg/models
# Configuration for genqlient's smart-casing.
#
# By default genqlient tries to convert GraphQL type names to Go style
# automatically. Sometimes it doesn't do a great job; this suite of options
# lets you configure its algorithm as makes sense for your schema.
#
# Options below support the following values:
# - default: use genqlient's default algorithm, which tries to convert GraphQL
# names to exported Go names. This is usually best for GraphQL schemas using
# idiomatic GraphQL types.
# - raw: map the GraphQL type exactly; don't try to convert it to Go style.
# This is usually best for schemas with casing conflicts, e.g. enums with
# values which differ only in casing.
casing:
# Use the given casing-style (see above) for all GraphQL enum values.
all_enums: raw
# Use the given casing-style (see above) for the enum values in the given
# GraphQL types (takes precedence over all_enum_values).
enums:
MyEnum: raw