Skip to content

Commit 6d966ae

Browse files
authored
Add autoExhaustive types (#591)
* add autoExhaustive * upgrade rescript
1 parent d7edf3c commit 6d966ae

File tree

6 files changed

+67
-39
lines changed

6 files changed

+67
-39
lines changed

CHANGELOG.md

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

3+
- Add support for `autoExhaustiveTypes` config and a `@nonExhaustive` directive to control automatic exhaustive checks for unions/interfaces.
4+
35
# 4.0.0
46

57
- Support `@exhaustive` on interfaces as well.

packages/rescript-relay/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"react-dom": "18.2.0",
5757
"react-relay": "20.1.1",
5858
"relay-runtime": "20.1.1",
59-
"rescript": "12.0.0-rc.3"
59+
"rescript": "12.0.0"
6060
},
6161
"peerDependencies": {
6262
"@rescript/react": ">=0.13.0",

packages/rescript-relay/yarn.lock

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,40 +1351,40 @@
13511351
"@jridgewell/resolve-uri" "^3.0.3"
13521352
"@jridgewell/sourcemap-codec" "^1.4.10"
13531353

1354-
"@rescript/darwin-arm64@12.0.0-rc.3":
1355-
version "12.0.0-rc.3"
1356-
resolved "https://registry.yarnpkg.com/@rescript/darwin-arm64/-/darwin-arm64-12.0.0-rc.3.tgz#577f7dcdb8c15adcec75f8b9c2a1051961f78b65"
1357-
integrity sha512-d6OMJWnW8I9DgYPNw+9Gy72tOcgRqry+NkpVWYYU4+Ay/LAfCs1W+AWUmsKTlxwTe2JTLhXRX3HzrqXSQoC6tg==
1358-
1359-
"@rescript/darwin-x64@12.0.0-rc.3":
1360-
version "12.0.0-rc.3"
1361-
resolved "https://registry.yarnpkg.com/@rescript/darwin-x64/-/darwin-x64-12.0.0-rc.3.tgz#5a5f7c8efee669902bc3f3124c3a6953eed84d8c"
1362-
integrity sha512-ualm4FZRztHaxY7YbEbSgNQwBPRPEsyn30/xHSkuCY2CV7W7808H29X33bqnDkQZ1XxmnG3z2bz9UoZcJJnf6A==
1363-
1364-
"@rescript/linux-arm64@12.0.0-rc.3":
1365-
version "12.0.0-rc.3"
1366-
resolved "https://registry.yarnpkg.com/@rescript/linux-arm64/-/linux-arm64-12.0.0-rc.3.tgz#0b987c81148dd529bdd604e1f0a43a3829d5e642"
1367-
integrity sha512-StPyP+KHY1k2CQrVLV52VnQvgeQIKz8woEYB0JRL4LtYDb6g6jVj9aXiq6ZWyVo9vxas1zSCzCvzrXubIsgkmg==
1368-
1369-
"@rescript/linux-x64@12.0.0-rc.3":
1370-
version "12.0.0-rc.3"
1371-
resolved "https://registry.yarnpkg.com/@rescript/linux-x64/-/linux-x64-12.0.0-rc.3.tgz#d152131748ab4893eb4b7479ed84ad6935c36665"
1372-
integrity sha512-HB9K4huyr8zCET5BnUJQgskMpiJXERFc7P2mO0vDgMKgmDEmEeOVTUfFiO9aqCwFP/ujGFsWb47SEUxTmHOCcA==
1354+
"@rescript/darwin-arm64@12.0.0":
1355+
version "12.0.0"
1356+
resolved "https://registry.yarnpkg.com/@rescript/darwin-arm64/-/darwin-arm64-12.0.0.tgz#8462ce236354f6bf631384dff62dab986383dd2e"
1357+
integrity sha512-N2zNj/Uh0zrg8BJGWxdQjYTDf0d2ZV8D+Vmct8xORaUcEZvAkvZb+xA66UxP2QGhWmATcHmBth7oJ48xpWz/Vg==
1358+
1359+
"@rescript/darwin-x64@12.0.0":
1360+
version "12.0.0"
1361+
resolved "https://registry.yarnpkg.com/@rescript/darwin-x64/-/darwin-x64-12.0.0.tgz#7625fa4b8939957950c2e5f5a12e984e3a8a5e12"
1362+
integrity sha512-Qx/ao3Fl2lx3rF8mbRsyRK5HGAx8pmzyCdpSIAaUun5wLBnsJbNqgvqUH7VeI2TwaczHvcIljrYmnB7T5LJdFQ==
1363+
1364+
"@rescript/linux-arm64@12.0.0":
1365+
version "12.0.0"
1366+
resolved "https://registry.yarnpkg.com/@rescript/linux-arm64/-/linux-arm64-12.0.0.tgz#2e0f3c8dd61973ebd27482dbb8ea7c02858c4481"
1367+
integrity sha512-H65csj/0uqqjYy235m0h5CFxbrsas6RoVfjy5Xjf91Vyg/r5R/QIGQvhMtFvl4QojYsa1wXzXGcujwXh+S15xQ==
1368+
1369+
"@rescript/linux-x64@12.0.0":
1370+
version "12.0.0"
1371+
resolved "https://registry.yarnpkg.com/@rescript/linux-x64/-/linux-x64-12.0.0.tgz#09e6dd043de09b5e0aa632103b333c4b92e6ce72"
1372+
integrity sha512-WizQwyfMadxF096foZYU3I4zxcnNIc9XP7TP4fqdfe0v6OvQ5yHMI/uIfOsJ1GfNALce2UxvgS0pn67uxc55uA==
13731373

13741374
"@rescript/react@0.14.0":
13751375
version "0.14.0"
13761376
resolved "https://registry.yarnpkg.com/@rescript/react/-/react-0.14.0.tgz#f5733c2db6b103913a99f0f7c1a1db9d8e85509b"
13771377
integrity sha512-ncOHWK7ujQmff+QMYKRmtwETvJVolzkwRpDa0MFenEXdUz9ZYywNbq+xH9F9RDQeSwC3/4s9JeUQVyTu4fMpHw==
13781378

1379-
"@rescript/runtime@12.0.0-rc.3":
1380-
version "12.0.0-rc.3"
1381-
resolved "https://registry.yarnpkg.com/@rescript/runtime/-/runtime-12.0.0-rc.3.tgz#0e4ac1165d8edea1834ef06d33316069c6ae7fe2"
1382-
integrity sha512-Ihdnppw7A+ArLwfnLPcz04jh6ZaKADo0Rc6vMHYQ2+Dw+snO5VbxJ2As5ahVt9nUVL56w1k9pWgrIoLtb1eHcA==
1379+
"@rescript/runtime@12.0.0":
1380+
version "12.0.0"
1381+
resolved "https://registry.yarnpkg.com/@rescript/runtime/-/runtime-12.0.0.tgz#f33c6c6709cfc06551ada3a42a9def5954317b5f"
1382+
integrity sha512-STRbYHT5rnW61vWn2+Bdtj620XaprnoBSbPbkvOYZ+Zs8nfqtpBjhNw+JNpGQLXf73crk6MhxFGPxL2o5vb8TQ==
13831383

1384-
"@rescript/win32-x64@12.0.0-rc.3":
1385-
version "12.0.0-rc.3"
1386-
resolved "https://registry.yarnpkg.com/@rescript/win32-x64/-/win32-x64-12.0.0-rc.3.tgz#8cab1b8dbc367d11ac333eb1de20e45f34168614"
1387-
integrity sha512-Eyy61o6Wk3Cgiy/99zFCzxumL1WHOGEdbxU+ksqghuD3s2RgBWBobSygf3nhcoNBibXI0Fhpu+XXXoTOsTiQ9w==
1384+
"@rescript/win32-x64@12.0.0":
1385+
version "12.0.0"
1386+
resolved "https://registry.yarnpkg.com/@rescript/win32-x64/-/win32-x64-12.0.0.tgz#2a0194d80c14c8204422682a97720b01f4b5f2b1"
1387+
integrity sha512-kkqj4kQGbni5YglWoPm76M6hUuzKJHDEiLce5EZxW2Q4FrkS9dNRgm02c2Ck1cz/uKCS3m+ZoKQGIMMXTvo5Jw==
13881388

13891389
"@sinonjs/commons@^1.7.0":
13901390
version "1.8.3"
@@ -3775,18 +3775,18 @@ require-directory@^2.1.1:
37753775
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
37763776
integrity sha1-jGStX9MNqxyXbiNE/+f3kqam30I=
37773777

3778-
rescript@12.0.0-rc.3:
3779-
version "12.0.0-rc.3"
3780-
resolved "https://registry.yarnpkg.com/rescript/-/rescript-12.0.0-rc.3.tgz#69eff1a8ac02445169737d3c83d6a8e03def1bf5"
3781-
integrity sha512-8EOLvO6p5MxpprqpN4tbblfk6uJbz2Q5g/VHA7ii7TJu98JFNLehRjPNHhlEk2G4Lx+PZraSnGudTxBVmyLNoQ==
3778+
rescript@12.0.0:
3779+
version "12.0.0"
3780+
resolved "https://registry.yarnpkg.com/rescript/-/rescript-12.0.0.tgz#583ce5aa518b35b451f0b95bb18d90bdb9f59503"
3781+
integrity sha512-DGcZI2L5W0c6FuEnspLE0MIe1UtTt1VsW/vQfzBFCEBxSsQtoA6YRHUB8Puwnb30PHqZiFK1ADhn6UgA8LWK0A==
37823782
dependencies:
3783-
"@rescript/runtime" "12.0.0-rc.3"
3783+
"@rescript/runtime" "12.0.0"
37843784
optionalDependencies:
3785-
"@rescript/darwin-arm64" "12.0.0-rc.3"
3786-
"@rescript/darwin-x64" "12.0.0-rc.3"
3787-
"@rescript/linux-arm64" "12.0.0-rc.3"
3788-
"@rescript/linux-x64" "12.0.0-rc.3"
3789-
"@rescript/win32-x64" "12.0.0-rc.3"
3785+
"@rescript/darwin-arm64" "12.0.0"
3786+
"@rescript/darwin-x64" "12.0.0"
3787+
"@rescript/linux-arm64" "12.0.0"
3788+
"@rescript/linux-x64" "12.0.0"
3789+
"@rescript/win32-x64" "12.0.0"
37903790

37913791
resolve-cwd@^3.0.0:
37923792
version "3.0.0"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ module.exports = {
8787
// Enable this if you want mutations that return unions to always force selecting all union members. Read more in the docs on unions.
8888
autoExhaustiveMutations: true,
8989

90+
// Make these unions/interfaces exhaustive everywhere without adding @exhaustive manually.
91+
autoExhaustiveTypes: ["UserNameRenderer"],
92+
9093
// You can add type definitions for custom scalars here.
9194
// 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.
9295
customScalarTypes: {

rescript-relay-documentation/docs/unions.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,29 @@ roomOwner(roomId: $roomId) @exhaustive(disabled: true) {
156156

157157
You can also configure RescriptRelay to automatically apply exhaustiveness checking to mutation fields that return unions. Add `autoExhaustiveMutations: true` to your Relay configuration to enable this behavior for any top-level mutation field that returns a union type.
158158

159+
### Project-wide Exhaustive Types
160+
161+
If there are unions or interfaces you always want to handle exhaustively, list them in `autoExhaustiveTypes` in your `relay.config.js`:
162+
163+
```js
164+
module.exports = {
165+
// ...
166+
autoExhaustiveTypes: ["UserNameRenderer", "NameRenderable"],
167+
};
168+
```
169+
170+
Any field or fragment returning those types will be treated as if it had `@exhaustive` applied. When you need to opt out for a specific selection, add `@nonExhaustive`:
171+
172+
```graphql
173+
fragment UserName on User {
174+
nameRenderer @nonExhaustive {
175+
... on PlainUserNameRenderer { __typename }
176+
}
177+
}
178+
```
179+
180+
`@nonExhaustive` also disables automatic checks on mutations when `autoExhaustiveMutations` is enabled.
181+
159182
## Wrapping up
160183

161184
And that's that! Keep the following in mind about unions and everything will be fine:

0 commit comments

Comments
 (0)