thunder icon indicating copy to clipboard operation
thunder copied to clipboard

Add support for nullable enum types in schemaBuilder

Open felixweinberger opened this issue 3 years ago • 4 comments

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

felixweinberger avatar May 28 '21 13:05 felixweinberger

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 Coverage Status
Change from base Build 3414: -0.01%
Covered Lines: 6031
Relevant Lines: 9131

💛 - Coveralls

coveralls avatar May 28 '21 14:05 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.

felixweinberger avatar Jun 01 '21 09:06 felixweinberger

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

jl3329 avatar Jun 01 '21 17:06 jl3329

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.

jl3329 avatar Jun 01 '21 18:06 jl3329