Skip to content

Commit 8e7c8e4

Browse files
committed
support turning off future proof enums project wide
1 parent dec08c7 commit 8e7c8e4

6 files changed

Lines changed: 21 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# master
22

3+
- Respect `noFutureProofEnums` in generated ReScript enum types, disabling `FutureAddedValue(...)` when configured.
4+
- Fix issue with the non-React mode.
5+
36
# 4.2.3
47

58
- Actually wire up `autoExhaustiveTypes`.

rescript-relay-documentation/docs/enums.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ module Fragment = %relay(`
117117
`)
118118
```
119119

120+
> If you want to disable `FutureAddedValue(...)` project-wide, set `noFutureProofEnums: true` in `relay.config.js`. This removes the catch-all enum constructor from generated response enums everywhere. But you're strongly encouraged to keep it on, for safer code.
121+
120122
### Mapping strings to your enum
121123

122124
In addition to the utils listed above, there's also a function available for taking a string and mapping it to your enum, if it's valid. An example:

rescript-relay-documentation/docs/getting-started.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ module.exports = {
9090
// Make these unions/interfaces exhaustive everywhere without adding @exhaustive manually.
9191
autoExhaustiveTypes: ["UserNameRenderer"],
9292

93+
// Disable FutureAddedValue(...) for response enums project-wide.
94+
noFutureProofEnums: false,
95+
9396
// You can add type definitions for custom scalars here.
9497
// Whenever a custom scalar is encountered, the type emitted will correspond to the definition defined here. You can then deal with the type as needed when accessing the data.
9598
customScalarTypes: {

rescript-relay-documentation/docs/interfaces.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,12 @@ let make = (~book) => {
142142
}
143143
}
144144
```
145+
146+
## Safety and Exhaustiveness
147+
148+
Interfaces follow the same future-proofing model as unions when they are emitted as variants:
149+
150+
- By default, generated interface variants include `UnselectedUnionMember(string)`.
151+
- You can use `@exhaustive`, `@nonExhaustive`, `autoExhaustiveMutations`, and `autoExhaustiveTypes` just like for unions.
152+
153+
For more on those controls, see the [unions docs](unions).

rescript-relay-documentation/docs/unions.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ Any field or fragment returning those types will be treated as if it had `@exhau
172172
```graphql
173173
fragment UserName on User {
174174
nameRenderer @nonExhaustive {
175-
... on PlainUserNameRenderer { __typename }
175+
... on PlainUserNameRenderer {
176+
__typename
177+
}
176178
}
177179
}
178180
```

0 commit comments

Comments
 (0)