From d0ce239e787c39c179aa2e8af172faa6fc16cbe7 Mon Sep 17 00:00:00 2001 From: Graeme Coupar Date: Tue, 9 Jan 2024 11:42:51 +0000 Subject: [PATCH] Update docs & CHANGELOG after #795 --- CHANGELOG.md | 5 +++++ cynic-book/src/derives/enums.md | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b1d74a3..401ad7a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html ## Unreleased - xxxx-xx-xx +### New Features + +- `Enum`s can now opt out of exhaustiveness checking with the `non_exhaustive` + attribute + ## v3.3.3 - 2024-01-09 ### Bug Fixes diff --git a/cynic-book/src/derives/enums.md b/cynic-book/src/derives/enums.md index fd01b474..1048294f 100644 --- a/cynic-book/src/derives/enums.md +++ b/cynic-book/src/derives/enums.md @@ -24,6 +24,15 @@ smoothly, Cynic matches rust variants up to their equivalent specifying a `rename_all = "None"` attribute, or customised alternative `rename_all` values or individual `rename` attributes on the variants. +#### Exhaustiveness Checking + +By default, cynic checks the exhuastiveness of `Enum`s - you should provide a +variant for each enum value in the GraphQL schema. You can also provide a `fallback` variant to provide forwards compatability - if the server adds new enum values they'll be caught by this variant. + +You can opt-out of this exhaustiveness using the `#[cynic(non_exhaustive)]` +attribute. When this is present exhaustiveness is not checked, and the +fallback variant is used for all the variants missing from the selection. + #### Enum Attributes An Enum can be configured with several attributes on the enum itself: @@ -42,6 +51,9 @@ An Enum can be configured with several attributes on the enum itself: - `schema_module` tells cynic where to find your schema module. This is optional and should only be needed if your schema module is not in scope or is named something other than `schema`. +- `non_exhaustive` can be provided to mark an enum as non-exhaustive. Such + enums are required to have a fallback variant, but not required to have + a variant for each value in the schema.