Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# master

- Add support for `autoExhaustiveTypes` config and a `@nonExhaustive` directive to control automatic exhaustive checks for unions/interfaces.

# 4.0.0

- Support `@exhaustive` on interfaces as well.
Expand Down
2 changes: 1 addition & 1 deletion packages/rescript-relay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"react-dom": "18.2.0",
"react-relay": "20.1.1",
"relay-runtime": "20.1.1",
"rescript": "12.0.0-rc.3"
"rescript": "12.0.0"
},
"peerDependencies": {
"@rescript/react": ">=0.13.0",
Expand Down
74 changes: 37 additions & 37 deletions packages/rescript-relay/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1351,40 +1351,40 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"

"@rescript/[email protected]-rc.3":
version "12.0.0-rc.3"
resolved "https://registry.yarnpkg.com/@rescript/darwin-arm64/-/darwin-arm64-12.0.0-rc.3.tgz#577f7dcdb8c15adcec75f8b9c2a1051961f78b65"
integrity sha512-d6OMJWnW8I9DgYPNw+9Gy72tOcgRqry+NkpVWYYU4+Ay/LAfCs1W+AWUmsKTlxwTe2JTLhXRX3HzrqXSQoC6tg==

"@rescript/[email protected]-rc.3":
version "12.0.0-rc.3"
resolved "https://registry.yarnpkg.com/@rescript/darwin-x64/-/darwin-x64-12.0.0-rc.3.tgz#5a5f7c8efee669902bc3f3124c3a6953eed84d8c"
integrity sha512-ualm4FZRztHaxY7YbEbSgNQwBPRPEsyn30/xHSkuCY2CV7W7808H29X33bqnDkQZ1XxmnG3z2bz9UoZcJJnf6A==

"@rescript/[email protected]-rc.3":
version "12.0.0-rc.3"
resolved "https://registry.yarnpkg.com/@rescript/linux-arm64/-/linux-arm64-12.0.0-rc.3.tgz#0b987c81148dd529bdd604e1f0a43a3829d5e642"
integrity sha512-StPyP+KHY1k2CQrVLV52VnQvgeQIKz8woEYB0JRL4LtYDb6g6jVj9aXiq6ZWyVo9vxas1zSCzCvzrXubIsgkmg==

"@rescript/[email protected]-rc.3":
version "12.0.0-rc.3"
resolved "https://registry.yarnpkg.com/@rescript/linux-x64/-/linux-x64-12.0.0-rc.3.tgz#d152131748ab4893eb4b7479ed84ad6935c36665"
integrity sha512-HB9K4huyr8zCET5BnUJQgskMpiJXERFc7P2mO0vDgMKgmDEmEeOVTUfFiO9aqCwFP/ujGFsWb47SEUxTmHOCcA==
"@rescript/[email protected]":
version "12.0.0"
resolved "https://registry.yarnpkg.com/@rescript/darwin-arm64/-/darwin-arm64-12.0.0.tgz#8462ce236354f6bf631384dff62dab986383dd2e"
integrity sha512-N2zNj/Uh0zrg8BJGWxdQjYTDf0d2ZV8D+Vmct8xORaUcEZvAkvZb+xA66UxP2QGhWmATcHmBth7oJ48xpWz/Vg==

"@rescript/[email protected]":
version "12.0.0"
resolved "https://registry.yarnpkg.com/@rescript/darwin-x64/-/darwin-x64-12.0.0.tgz#7625fa4b8939957950c2e5f5a12e984e3a8a5e12"
integrity sha512-Qx/ao3Fl2lx3rF8mbRsyRK5HGAx8pmzyCdpSIAaUun5wLBnsJbNqgvqUH7VeI2TwaczHvcIljrYmnB7T5LJdFQ==

"@rescript/[email protected]":
version "12.0.0"
resolved "https://registry.yarnpkg.com/@rescript/linux-arm64/-/linux-arm64-12.0.0.tgz#2e0f3c8dd61973ebd27482dbb8ea7c02858c4481"
integrity sha512-H65csj/0uqqjYy235m0h5CFxbrsas6RoVfjy5Xjf91Vyg/r5R/QIGQvhMtFvl4QojYsa1wXzXGcujwXh+S15xQ==

"@rescript/[email protected]":
version "12.0.0"
resolved "https://registry.yarnpkg.com/@rescript/linux-x64/-/linux-x64-12.0.0.tgz#09e6dd043de09b5e0aa632103b333c4b92e6ce72"
integrity sha512-WizQwyfMadxF096foZYU3I4zxcnNIc9XP7TP4fqdfe0v6OvQ5yHMI/uIfOsJ1GfNALce2UxvgS0pn67uxc55uA==

"@rescript/[email protected]":
version "0.14.0"
resolved "https://registry.yarnpkg.com/@rescript/react/-/react-0.14.0.tgz#f5733c2db6b103913a99f0f7c1a1db9d8e85509b"
integrity sha512-ncOHWK7ujQmff+QMYKRmtwETvJVolzkwRpDa0MFenEXdUz9ZYywNbq+xH9F9RDQeSwC3/4s9JeUQVyTu4fMpHw==

"@rescript/[email protected]-rc.3":
version "12.0.0-rc.3"
resolved "https://registry.yarnpkg.com/@rescript/runtime/-/runtime-12.0.0-rc.3.tgz#0e4ac1165d8edea1834ef06d33316069c6ae7fe2"
integrity sha512-Ihdnppw7A+ArLwfnLPcz04jh6ZaKADo0Rc6vMHYQ2+Dw+snO5VbxJ2As5ahVt9nUVL56w1k9pWgrIoLtb1eHcA==
"@rescript/[email protected]":
version "12.0.0"
resolved "https://registry.yarnpkg.com/@rescript/runtime/-/runtime-12.0.0.tgz#f33c6c6709cfc06551ada3a42a9def5954317b5f"
integrity sha512-STRbYHT5rnW61vWn2+Bdtj620XaprnoBSbPbkvOYZ+Zs8nfqtpBjhNw+JNpGQLXf73crk6MhxFGPxL2o5vb8TQ==

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

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

[email protected]-rc.3:
version "12.0.0-rc.3"
resolved "https://registry.yarnpkg.com/rescript/-/rescript-12.0.0-rc.3.tgz#69eff1a8ac02445169737d3c83d6a8e03def1bf5"
integrity sha512-8EOLvO6p5MxpprqpN4tbblfk6uJbz2Q5g/VHA7ii7TJu98JFNLehRjPNHhlEk2G4Lx+PZraSnGudTxBVmyLNoQ==
[email protected]:
version "12.0.0"
resolved "https://registry.yarnpkg.com/rescript/-/rescript-12.0.0.tgz#583ce5aa518b35b451f0b95bb18d90bdb9f59503"
integrity sha512-DGcZI2L5W0c6FuEnspLE0MIe1UtTt1VsW/vQfzBFCEBxSsQtoA6YRHUB8Puwnb30PHqZiFK1ADhn6UgA8LWK0A==
dependencies:
"@rescript/runtime" "12.0.0-rc.3"
"@rescript/runtime" "12.0.0"
optionalDependencies:
"@rescript/darwin-arm64" "12.0.0-rc.3"
"@rescript/darwin-x64" "12.0.0-rc.3"
"@rescript/linux-arm64" "12.0.0-rc.3"
"@rescript/linux-x64" "12.0.0-rc.3"
"@rescript/win32-x64" "12.0.0-rc.3"
"@rescript/darwin-arm64" "12.0.0"
"@rescript/darwin-x64" "12.0.0"
"@rescript/linux-arm64" "12.0.0"
"@rescript/linux-x64" "12.0.0"
"@rescript/win32-x64" "12.0.0"

resolve-cwd@^3.0.0:
version "3.0.0"
Expand Down
3 changes: 3 additions & 0 deletions rescript-relay-documentation/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ module.exports = {
// Enable this if you want mutations that return unions to always force selecting all union members. Read more in the docs on unions.
autoExhaustiveMutations: true,

// Make these unions/interfaces exhaustive everywhere without adding @exhaustive manually.
autoExhaustiveTypes: ["UserNameRenderer"],

// You can add type definitions for custom scalars here.
// 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.
customScalarTypes: {
Expand Down
23 changes: 23 additions & 0 deletions rescript-relay-documentation/docs/unions.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,29 @@ roomOwner(roomId: $roomId) @exhaustive(disabled: true) {

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.

### Project-wide Exhaustive Types

If there are unions or interfaces you always want to handle exhaustively, list them in `autoExhaustiveTypes` in your `relay.config.js`:

```js
module.exports = {
// ...
autoExhaustiveTypes: ["UserNameRenderer", "NameRenderable"],
};
```

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`:

```graphql
fragment UserName on User {
nameRenderer @nonExhaustive {
... on PlainUserNameRenderer { __typename }
}
}
```

`@nonExhaustive` also disables automatic checks on mutations when `autoExhaustiveMutations` is enabled.

## Wrapping up

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