Skip to content

Use @nonexhaustive for codegen in enums #3584

@thomascatterall-toast

Description

@thomascatterall-toast

Use case

Extensible enums has been accepted and would make a great addition to the codegen options.

Currently you have to dance around either:
switching directly on the GraphQLEnum, which requires a default case
unwrapping directly the enum and exhaustively checking

When the enum changes in the schema, the first option provides no warning that your code has a new case to consider; the latter breaks the code entirely. Neither are great options.

This attribute is explicitly for the use case of public API that may be extended later, and provides the same behavior as non frozen enums in Library Evolution-enabled modules (which are very much a niche).

The end result would be that all gql enums could be switched over directly (you could drop the GraphQLEnum type, eventually) and would require an @unknown default case. Furthermore, you would receive a compiler warning when you had not handled a new case.

Describe the solution you'd like

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew addition or enhancement to existing solutions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions