thunder
thunder copied to clipboard
Add support for nullable enum types in schemaBuilder
graphql: add support for nullable enum types in schemaBuilder When generating schema.json, we handle Enums only if they are non-nullable. If we supply a *EnumType (i.e. a pointer to an Enum), we end up defaulting to the SCALAR type for that enum on a query.
This commit adds support for nullable enums to our schema generation, ensuring that enum types are reflected correctly in the schema even if they are marked as optional through use of a pointer.
Note that:
- Nullable enums can already be used as arguments to queries
- This commit adds support for nullable enum types in the query return
Pull Request Test Coverage Report for Build 3448
- 1 of 3 (33.33%) changed or added relevant lines in 1 file are covered.
- 4 unchanged lines in 1 file lost coverage.
- Overall coverage decreased (-0.01%) to 66.05%
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
---|---|---|---|
graphql/schemabuilder/build.go | 1 | 3 | 33.33% |
<!-- | Total: | 1 | 3 |
Files with Coverage Reduction | New Missed Lines | % |
---|---|---|
graphql/schemabuilder/input.go | 4 | 59.83% |
<!-- | Total: | 4 |
Totals | |
---|---|
Change from base Build 3414: | -0.01% |
Covered Lines: | 6031 |
Relevant Lines: | 9131 |
💛 - Coveralls
This LGTM. Would you mind clarifying in the commit message that we are adding support for nullable enum types in the return value, and that nullable enums can already be used as arguments?
Added comments to point this out in the commit description.
As you noted in our conversation, this is a breaking change because this can potentially change the return value type if there are existing endpoints that return a pointer to a go enum. Let's put that in the commit message PR description somewhere so that it's clear
Going to remove approval for now until we can safely apply this change to the Samsara repo. This is a breaking change because this changes the schema's return type for existing field funcs that return a pointer to a Go enum.
In order to make this change safely, we must change all of these existing field funcs to instead return a pointer to the underlying scalar type so that the return types do not change in the schema.